mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
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:
@@ -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) ?? ""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user