diff options
| author | Igor Soarez <igor@soarez.org> | 2026-10-30 17:27:21 +0200 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-10-30 17:27:21 +0200 |
| commit | b0cfd10b80443d3f67d263ff4db177bb53cc90ed (patch) | |
| tree | 957951350434f38da83457f5467b6c000e892867 /menubar/model.swift | |
| parent | 91436536b69c10aa333c2b2978284b57cca3ed64 (diff) | |
reload pi agents on an old extension: versioned extension, control socket, menu item and reload-agents
Diffstat (limited to 'menubar/model.swift')
| -rw-r--r-- | menubar/model.swift | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/menubar/model.swift b/menubar/model.swift index f0f977e..e4d179c 100644 --- a/menubar/model.swift +++ b/menubar/model.swift @@ -230,6 +230,37 @@ func fetchRestoreOffer() -> RestoreOffer? { return try? JSONDecoder().decode(RestoreOffer.self, from: data) } +// MARK: agents on an old extension + +/// pi agents on an old dingger extension, as the daemon counts them: +/// `@dingger_outdated` it can reload, `@dingger_outdated_by_hand` it cannot +/// (an extension from before reloads). +struct OutdatedAgents: Equatable { + let reloadable: Int + let byHand: Int + + var isEmpty: Bool { reloadable == 0 && byHand == 0 } + var canReload: Bool { reloadable > 0 } + + private func agents(_ n: Int) -> String { "\(n) \(n == 1 ? "Agent" : "Agents")" } + + /// "Reload 3 Agents on an Old Extension", or "2 Agents Need /reload". + var title: String { + canReload ? "Reload \(agents(reloadable)) on an Old Extension" : "\(agents(byHand)) \(byHand == 1 ? "Needs" : "Need") /reload" + } + + var detail: String { + guard canReload else { return "their dingger extension is too old to reload them" } + let when = "each when idle and off screen" + return byHand > 0 ? "\(when) ยท \(byHand) more need /reload" : when + } +} + +func fetchOutdated() -> OutdatedAgents { + let count = { (name: String) in Int(tmux(["show-options", "-gv", name])?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "") ?? 0 } + return OutdatedAgents(reloadable: count("@dingger_outdated"), byHand: count("@dingger_outdated_by_hand")) +} + /// Run `dingger <args>` through the user's login shell, the way a terminal /// starts tmux: restored panes inherit this environment (PATH, LANG), and /// launchd's is bare. DINGGER_RESTORE_DIRECT runs it directly (tests). |
