Inkspring / app · inkspring.ai / native-mac / Sources / Inkspring / InkspringUpdates.swift
| 1 | import Foundation |
| 2 | import Observation |
| 3 | import Sparkle |
| 4 | |
| 5 | @MainActor |
| 6 | @Observable |
| 7 | final 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 | } |