mirror of
https://github.com/yattee/yattee.git
synced 2024-12-23 05:53:41 +00:00
42 lines
1.1 KiB
Swift
42 lines
1.1 KiB
Swift
|
import Defaults
|
||
|
import Sparkle
|
||
|
import SwiftUI
|
||
|
|
||
|
final class UpdaterModel: ObservableObject {
|
||
|
@Published var canCheckForUpdates = false
|
||
|
|
||
|
private let updaterController: SPUStandardUpdaterController
|
||
|
private let updaterDelegate = UpdaterDelegate()
|
||
|
|
||
|
init() {
|
||
|
updaterController = SPUStandardUpdaterController(
|
||
|
startingUpdater: true,
|
||
|
updaterDelegate: updaterDelegate,
|
||
|
userDriverDelegate: nil
|
||
|
)
|
||
|
|
||
|
updaterController.updater.publisher(for: \.canCheckForUpdates)
|
||
|
.assign(to: &$canCheckForUpdates)
|
||
|
}
|
||
|
|
||
|
func checkForUpdates() {
|
||
|
updaterController.checkForUpdates(nil)
|
||
|
}
|
||
|
|
||
|
var automaticallyChecksForUpdates: Bool {
|
||
|
updaterController.updater.automaticallyChecksForUpdates
|
||
|
}
|
||
|
|
||
|
func setAutomaticallyChecksForUpdates(_ value: Bool) {
|
||
|
updaterController.updater.automaticallyChecksForUpdates = value
|
||
|
}
|
||
|
}
|
||
|
|
||
|
final class UpdaterDelegate: NSObject, SPUUpdaterDelegate {
|
||
|
@Default(.enableBetaChannel) private var enableBetaChannel
|
||
|
|
||
|
func allowedChannels(for _: SPUUpdater) -> Set<String> {
|
||
|
Set(enableBetaChannel ? ["beta"] : [])
|
||
|
}
|
||
|
}
|