Commit 34152a1a3b

34152a1a3b41e75eef3f5c1a2ff038ac7a4cd1db

parent: fe31f1cd94

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-11 05:06 UTC

Check for Updates… and automatic checks

Layout: unified · split

Sources/Orgstar/OrgstarApp.swift +15 −1
@@ -162,9 +162,11 @@ struct PromptRequest: Identifiable {
162162final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate {
163163 var session: DocumentSession?
164164 var commands: AppCommands?
165 let updates = Updates()
165166
166167 func applicationDidFinishLaunching(_ notification: Notification) {
167168 if SystemReminderCenter.isAvailable { UNUserNotificationCenter.current().delegate = self }
169 updates.start()
168170 }
169171
170172 /// `:session` interpreters end with the app.
@@ -462,9 +464,12 @@ struct OrgstarApp: App {
462464 Button("Edit Config File") { commands.jump(path: UserConfig.configFile.path, offset: 0) }
463465 .keyboardShortcut(",", modifiers: [.command, .option])
464466 }
467 CommandGroup(after: .appInfo) {
468 CheckForUpdatesItem(updates: delegate.updates)
469 }
465470 }
466471 Settings {
467 SettingsView(commands: commands, workspace: try? workspace.get())
472 SettingsView(commands: commands, workspace: try? workspace.get(), updates: delegate.updates)
468473 }
469474 }
470475}
@@ -537,6 +542,7 @@ struct AgendaMenuItem: View {
537542struct SettingsView: View {
538543 let commands: AppCommands
539544 let workspace: WorkspaceModel?
545 let updates: Updates
540546 @State private var importing = false
541547 @Environment(\.openWindow) private var openWindow
542548 @AppStorage("saveMode") private var saveMode = SaveMode.automatic
@@ -612,6 +618,14 @@ struct SettingsView: View {
612618 Text("Every setting here is also in \(UserConfig.configFile.path), which you can edit, share or keep with your dotfiles. Changes in either place show up in the other.")
613619 .settingsFooter()
614620 }
621 if updates.canCheck {
622 Section {
623 Toggle("Check for updates automatically", isOn: Binding(get: { updates.automatically }, set: { updates.automatically = $0 }))
624 } footer: {
625 Text("Once a day, from the app's own feed. orgstar ▸ Check for Updates… checks now.")
626 .settingsFooter()
627 }
628 }
615629 Section {
616630 Picker("Save files", selection: $saveMode) {
617631 Text("Automatically, when typing stops").tag(SaveMode.automatic)
Sources/Orgstar/Updates.swift added +42
@@ -0,0 +1,42 @@
1import Combine
2import Sparkle
3import SwiftUI
4
5/// Sparkle, for the signed builds: the Info.plist names the appcast and the key the DMGs are
6/// signed with. A dev build has neither, so the updater doesn't start and the menu item stays
7/// disabled. Whether to check automatically is Sparkle's own setting, asked once on the
8/// second launch.
9@MainActor
10@Observable
11final class Updates {
12 private(set) var canCheck = false
13 @ObservationIgnored private var controller: SPUStandardUpdaterController?
14 @ObservationIgnored private var observation: AnyCancellable?
15
16 func start() {
17 guard controller == nil, Bundle.main.object(forInfoDictionaryKey: "SUFeedURL") != nil else { return }
18 let controller = SPUStandardUpdaterController(startingUpdater: true, updaterDelegate: nil, userDriverDelegate: nil)
19 self.controller = controller
20 observation = controller.updater.publisher(for: \.canCheckForUpdates).sink { [weak self] can in
21 MainActor.assumeIsolated { self?.canCheck = can }
22 }
23 }
24
25 func check() {
26 controller?.updater.checkForUpdates()
27 }
28
29 var automatically: Bool {
30 get { controller?.updater.automaticallyChecksForUpdates ?? false }
31 set { controller?.updater.automaticallyChecksForUpdates = newValue }
32 }
33}
34
35struct CheckForUpdatesItem: View {
36 let updates: Updates
37
38 var body: some View {
39 Button("Check for Updates…") { updates.check() }
40 .disabled(!updates.canCheck)
41 }
42}