Add prefs to Advanced prefs pane to 1) check for updates automatically, and 2) choose to download test or release builds. The default will be release builds only, since most people don’t want test builds.

This commit is contained in:
Brent Simmons
2019-08-18 16:07:37 -07:00
parent 5670989c29
commit 588dbb0ce5
2 changed files with 141 additions and 43 deletions

View File

@@ -10,5 +10,56 @@ import AppKit
final class AdvancedPreferencesViewController: NSViewController {
@IBOutlet var releaseBuildsButton: NSButton!
@IBOutlet var testBuildsButton: NSButton!
let releaseBuildsURL = Bundle.main.infoDictionary!["SUFeedURL"]! as! String
let testBuildsURL = Bundle.main.infoDictionary!["FeedURLForTestBuilds"]! as! String
let appcastDefaultsKey = "SUFeedURL"
var didRegisterForNotification = false
var wantsTestBuilds: Bool {
get {
return currentAppcastURL() == testBuildsURL
}
set {
UserDefaults.standard.set(newValue ? testBuildsURL : releaseBuildsURL, forKey: appcastDefaultsKey)
}
}
override func viewWillAppear() {
super.viewWillAppear()
updateUI()
if !didRegisterForNotification {
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
didRegisterForNotification = true
}
}
@IBAction func updateTypeButtonClicked(_ sender: Any?) {
guard let button = sender as? NSButton else {
return
}
wantsTestBuilds = (button === testBuildsButton)
}
@objc func userDefaultsDidChange(_ sender: Any?) {
updateUI()
}
}
private extension AdvancedPreferencesViewController {
func updateUI() {
if wantsTestBuilds {
testBuildsButton.state = .on
}
else {
releaseBuildsButton.state = .on
}
}
func currentAppcastURL() -> String {
return UserDefaults.standard.string(forKey: appcastDefaultsKey) ?? ""
}
}