diff --git a/README.md b/README.md index 6d37e0b..7a91882 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ know whether you're up to date or to start an update. | Item | Runs | What you see | | --- | --- | --- | | Header | `git log` on `~/.local/share/coredesktop` | Your version, e.g. `2026.11.25 (4fb3539)`, and one status line: *Up to date*, *2026.11.27 (f798974) is available*, *Updating…*, *Restart to finish the last update* | -| Restart to finish updating | `gnome-session-quit --reboot` | Shown only while `~/.local/state/coredesktop/reboot-needed` exists | +| Restart to finish updating | `gnome-session-quit --reboot` | Shown only while `~/.local/state/coredesktop/reboot-needed` exists and was written since the last boot | | Update | `update` in a terminal | **New version** pill when `version --check` finds one; **Running…** while it runs | | Refresh | `refresh` in a terminal | First, a dialog explaining what refresh does (this can be turned off) | | Sibling projects | `sibling check --porcelain` | Shown only if you have sibling projects. Says which have a newer version, with an **N new** pill. Opens a dialog listing each sibling's installed version and **Up to date**, **New version** or **Couldn't check**, with an **Update** button that runs `sibling update ` in a terminal (and **Update all** for `sibling update`) | diff --git a/coredesktop@federated.computer/extension.js b/coredesktop@federated.computer/extension.js index e64044b..9522694 100644 --- a/coredesktop@federated.computer/extension.js +++ b/coredesktop@federated.computer/extension.js @@ -345,7 +345,7 @@ class Indicator extends PanelMenu.Button { this._header.versionLabel.text = version ?? (Cli.isInstalled() ? 'Version unknown' : 'CoreDesktop isn\'t installed'); - this._rebootNeeded = GLib.file_test(Cli.REBOOT_NEEDED, GLib.FileTest.EXISTS); + this._rebootNeeded = Cli.rebootNeeded(); this._lastUpdate = Cli.mtime(Cli.PACMAN_UPDATE_LOG); const names = await Cli.installedSiblings(); diff --git a/coredesktop@federated.computer/lib/cli.js b/coredesktop@federated.computer/lib/cli.js index 2f6339a..e610b4a 100644 --- a/coredesktop@federated.computer/lib/cli.js +++ b/coredesktop@federated.computer/lib/cli.js @@ -207,6 +207,28 @@ export function mtime(path) { } } +// When this boot started, in seconds since the epoch, from btime in /proc/stat +export function bootTime() { + try { + const [, contents] = GLib.file_get_contents('/proc/stat'); + const match = new TextDecoder().decode(contents).match(/^btime (\d+)$/m); + return match ? Number(match[1]) : null; + } catch { + return null; + } +} + +// Whether the last update asked for a restart that hasn't happened yet. +// CoreDesktop only removes the flag at the start of the next update, so a +// flag written before this boot is already satisfied. +export function rebootNeeded() { + const flagged = mtime(REBOOT_NEEDED); + if (flagged === null) + return false; + const booted = bootTime(); + return booted === null || flagged >= booted; +} + export function findTerminal(preference) { if (preference && preference !== 'auto') { if (GLib.find_program_in_path(preference))