Initialize Sparkle based on UserDefaults

This commit is contained in:
Angelo Stavrow 2020-12-23 15:00:44 -05:00
parent a169265707
commit 30b3a446d7
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 19 additions and 8 deletions

View File

@ -2,12 +2,23 @@ import Cocoa
import Sparkle
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
SUUpdater.shared()?.automaticallyChecksForUpdates = true
/*
Next line prints:
You must specify the URL of the appcast as the SUFeedURL key in either the Info.plist or the user defaults!
*/
SUUpdater.shared()?.checkForUpdates(self)
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()?.checkForUpdates(self)
}
}
}

View File

@ -1,7 +1,7 @@
import SwiftUI
import Sparkle
private enum AppcastFeedUrl: String {
enum AppcastFeedUrl: String {
case release = "https://files.writefreely.org/apps/mac/appcast.xml"
case beta = "https://files.writefreely.org/apps/mac/appcast-beta.xml"
}