fix: auto-update preferences sync with os from launch
This commit is contained in:
1 parent
f950083061
commit
b3fb222d7f
2 files changed
+10
-12
No files matched your search
+4
-5
@@ -28,7 +28,7 @@ class App: NSApplication, NSApplicationDelegate {
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
#if !DEBUG
|
||||
PFMoveToApplicationsFolderIfNecessary()
|
||||
PFMoveToApplicationsFolderIfNecessary()
|
||||
#endif
|
||||
SystemPermissions.ensureAccessibilityCheckboxIsChecked()
|
||||
SystemPermissions.ensureScreenRecordingCheckboxIsChecked()
|
||||
@@ -39,6 +39,8 @@ class App: NSApplication, NSApplicationDelegate {
|
||||
Spaces.initialDiscovery()
|
||||
Applications.initialDiscovery()
|
||||
Keyboard.listenToGlobalEvents(self)
|
||||
preferencesWindow = PreferencesWindow()
|
||||
UpdatesTab.observeUserDefaults()
|
||||
}
|
||||
|
||||
// keyboard shortcuts are broken without a menu. We generated the default menu from XCode and load it
|
||||
@@ -46,7 +48,7 @@ class App: NSApplication, NSApplicationDelegate {
|
||||
private func loadMainMenuXib() {
|
||||
var menuObjects: NSArray?
|
||||
Bundle.main.loadNibNamed("MainMenu", owner: self, topLevelObjects: &menuObjects)
|
||||
menu = menuObjects?.first(where: {$0 is NSMenu }) as? NSMenu
|
||||
menu = menuObjects?.first(where: { $0 is NSMenu }) as? NSMenu
|
||||
}
|
||||
|
||||
// we put application code here which should be executed on init() and Preferences change
|
||||
@@ -77,9 +79,6 @@ class App: NSApplication, NSApplicationDelegate {
|
||||
|
||||
@objc
|
||||
func showPreferencesPanel() {
|
||||
if preferencesWindow == nil {
|
||||
preferencesWindow = PreferencesWindow()
|
||||
}
|
||||
Screen.repositionPanel(preferencesWindow!, Screen.preferred(), .appleCentered)
|
||||
preferencesWindow?.show()
|
||||
}
|
||||
|
||||
@@ -13,7 +13,12 @@ class UpdatesTab: NSObject {
|
||||
return TabViewItem.make(NSLocalizedString("Updates", comment: ""), NSImage.refreshTemplateName, makeView())
|
||||
}
|
||||
|
||||
static func makeView() -> NSGridView {
|
||||
static func observeUserDefaults() {
|
||||
UserDefaults.standard.addObserver(UpdatesTab.policyObserver, forKeyPath: "SUAutomaticallyUpdate", options: [.initial, .new], context: nil)
|
||||
UserDefaults.standard.addObserver(UpdatesTab.policyObserver, forKeyPath: "SUEnableAutomaticChecks", options: [.initial, .new], context: nil)
|
||||
}
|
||||
|
||||
static private func makeView() -> NSGridView {
|
||||
dontPeriodicallyCheck = NSButton(radioButtonWithTitle: NSLocalizedString("Don't check for updates periodically", comment: ""), target: self, action: #selector(updatePolicyCallback))
|
||||
dontPeriodicallyCheck.fit()
|
||||
periodicallyCheck = NSButton(radioButtonWithTitle: NSLocalizedString("Check for updates periodically", comment: ""), target: self, action: #selector(updatePolicyCallback))
|
||||
@@ -25,7 +30,6 @@ class UpdatesTab: NSObject {
|
||||
policies.alignment = .left
|
||||
policies.orientation = .vertical
|
||||
policies.spacing = GridView.interPadding / 2
|
||||
observePolicy()
|
||||
let view = GridView.make([
|
||||
[policyLabel, policies],
|
||||
[NSButton(title: NSLocalizedString("Check for updates now…", comment: ""), target: self, action: #selector(checkForUpdatesNow))],
|
||||
@@ -39,11 +43,6 @@ class UpdatesTab: NSObject {
|
||||
return view
|
||||
}
|
||||
|
||||
private static func observePolicy() {
|
||||
UserDefaults.standard.addObserver(UpdatesTab.policyObserver, forKeyPath: "SUAutomaticallyUpdate", options: [.initial, .new], context: nil)
|
||||
UserDefaults.standard.addObserver(UpdatesTab.policyObserver, forKeyPath: "SUEnableAutomaticChecks", options: [.initial, .new], context: nil)
|
||||
}
|
||||
|
||||
@objc
|
||||
static func checkForUpdatesNow(_ sender: Any) {
|
||||
SUUpdater.shared().checkForUpdates(sender)
|
||||
|
||||
Reference in new issue
Block a user