swiftui-multiplatform/macOS/AppDelegate.swift

25 lines
1.1 KiB
Swift
Raw Normal View History

2020-12-22 20:06:25 +00:00
import Cocoa
import Sparkle
2020-12-22 20:06:25 +00:00
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationWillFinishLaunching(_ notification: Notification) {
// Check UserDefaults for values; if the key doesn't exist (e.g., if MacUpdatesView hasn't ever been shown),
// bool(forKey:) returns false, so set SUUpdater.shared() appropriately.
let automaticallyChecksForUpdates = UserDefaults.standard.bool(forKey: "automaticallyChecksForUpdates")
let subscribeToBetaUpdates = UserDefaults.standard.bool(forKey: "subscribeToBetaUpdates")
// Set Sparkle properties.
SUUpdater.shared()?.automaticallyChecksForUpdates = automaticallyChecksForUpdates
if subscribeToBetaUpdates {
SUUpdater.shared()?.feedURL = URL(string: AppcastFeedUrl.beta.rawValue)
} else {
SUUpdater.shared()?.feedURL = URL(string: AppcastFeedUrl.release.rawValue)
}
// If enabled, check for updates.
if automaticallyChecksForUpdates {
SUUpdater.shared()?.checkForUpdatesInBackground()
}
2020-12-22 20:06:25 +00:00
}
}