diff --git a/macOS/AppDelegate.swift b/macOS/AppDelegate.swift index b44a890..f23d06e 100644 --- a/macOS/AppDelegate.swift +++ b/macOS/AppDelegate.swift @@ -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) + } } } diff --git a/macOS/Settings/MacUpdatesView.swift b/macOS/Settings/MacUpdatesView.swift index deee83b..c72f488 100644 --- a/macOS/Settings/MacUpdatesView.swift +++ b/macOS/Settings/MacUpdatesView.swift @@ -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" }