mirror of
https://github.com/yattee/yattee.git
synced 2025-10-17 21:08:16 +00:00
Add Sparkle update framework for macOS
This commit is contained in:
41
macOS/Updates/UpdaterModel.swift
Normal file
41
macOS/Updates/UpdaterModel.swift
Normal file
@@ -0,0 +1,41 @@
|
||||
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"] : [])
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user