diff --git a/src/ui/App.swift b/src/ui/App.swift index cb360828..6986922b 100644 --- a/src/ui/App.swift +++ b/src/ui/App.swift @@ -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() } diff --git a/src/ui/preferences-window/tabs/UpdatesTab.swift b/src/ui/preferences-window/tabs/UpdatesTab.swift index 4c3b3c85..40a4d6aa 100644 --- a/src/ui/preferences-window/tabs/UpdatesTab.swift +++ b/src/ui/preferences-window/tabs/UpdatesTab.swift @@ -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)