aboutsummaryrefslogtreecommitdiff
path: root/menubar/model.swift
diff options
context:
space:
mode:
Diffstat (limited to 'menubar/model.swift')
-rw-r--r--menubar/model.swift31
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).