Branchwell

Inkspring / app · inkspring.ai / native-mac / Sources / Inkspring / InkspringUpdates.swift

Raw 999 B on 332c2458022ae8f6648ea05f3c733b528a595172
1import Foundation
2import Observation
3import Sparkle
4
5@MainActor
6@Observable
7final class InkspringUpdates {
8 let isConfigured = Bundle.main.object(forInfoDictionaryKey: "SUFeedURL") is String
9 private(set) var canCheck = false
10 private var controller: SPUStandardUpdaterController?
11 private var availability: NSKeyValueObservation?
12
13 func start() {
14 guard isConfigured, controller == nil else { return }
15 let controller = SPUStandardUpdaterController(
16 startingUpdater: false, updaterDelegate: nil, userDriverDelegate: nil
17 )
18 self.controller = controller
19 availability = controller.updater.observe(\.canCheckForUpdates, options: [.initial, .new]) { [weak self] _, _ in
20 Task { @MainActor [weak self] in
21 self?.canCheck = self?.controller?.updater.canCheckForUpdates == true
22 }
23 }
24 controller.startUpdater()
25 }
26
27 func check() {
28 controller?.updater.checkForUpdates()
29 }
30}