38 lines
1.3 KiB
Swift
38 lines
1.3 KiB
Swift
import Foundation
|
|
import Sparkle
|
|
|
|
@MainActor
|
|
final class UpdateController: ObservableObject {
|
|
let updaterController: SPUStandardUpdaterController?
|
|
|
|
init() {
|
|
let feed = Bundle.main.object(forInfoDictionaryKey: "SUFeedURL") as? String
|
|
let publicKey = Bundle.main.object(forInfoDictionaryKey: "SUPublicEDKey") as? String
|
|
if let feed, !feed.isEmpty, let publicKey, !publicKey.isEmpty {
|
|
updaterController = SPUStandardUpdaterController(
|
|
startingUpdater: true,
|
|
updaterDelegate: nil,
|
|
userDriverDelegate: nil
|
|
)
|
|
} else {
|
|
updaterController = nil
|
|
}
|
|
}
|
|
|
|
var isConfigured: Bool { updaterController != nil }
|
|
var canCheckForUpdates: Bool { updaterController?.updater.canCheckForUpdates ?? false }
|
|
var automaticallyChecksForUpdates: Bool {
|
|
get { updaterController?.updater.automaticallyChecksForUpdates ?? false }
|
|
set { updaterController?.updater.automaticallyChecksForUpdates = newValue }
|
|
}
|
|
var automaticallyDownloadsUpdates: Bool {
|
|
get { updaterController?.updater.automaticallyDownloadsUpdates ?? false }
|
|
set { updaterController?.updater.automaticallyDownloadsUpdates = newValue }
|
|
}
|
|
|
|
func checkForUpdates() {
|
|
updaterController?.checkForUpdates(nil)
|
|
objectWillChange.send()
|
|
}
|
|
}
|