diff --git a/phpmon-common/Core/Actions.swift b/phpmon-common/Core/Actions.swift index bb5163a..11467a0 100644 --- a/phpmon-common/Core/Actions.swift +++ b/phpmon-common/Core/Actions.swift @@ -74,6 +74,19 @@ class Actions { .appendingPathComponent(".config/valet") NSWorkspace.shared.activateFileViewerSelecting([file] as [URL]) } + + // MARK: - Other Actions + + public static func createTempPhpInfoFile() -> URL + { + // Write a file called `phpmon_phpinfo.php` to /tmp + try! " /tmp/phpmon_phpinfo.html") + + return URL(string: "file:///private/tmp/phpmon_phpinfo.html")! + } // MARK: - Quick Fix diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index 8cbb51f..f7f4dd9 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -307,34 +307,38 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { waitAndExecute { sender.phpExtension?.toggle() - if Preferences.preferences[.autoServiceRestartAfterExtensionToggle] as! Bool == true { + if Preferences.isTrue(.autoServiceRestartAfterExtensionToggle) { Actions.restartPhpFpm() } } } @objc func openPhpInfo() { + var url: URL? = nil + waitAndExecute { - // Write a file called `phpmon_phpinfo.php` to /tmp - try! " /tmp/phpmon_phpinfo.html") + url = Actions.createTempPhpInfoFile() } completion: { // When this has been completed, open the URL to the file in the browser - NSWorkspace.shared.open(URL(string: "file:///private/tmp/phpmon_phpinfo.html")!) + NSWorkspace.shared.open(url!) } } @objc func forceRestartLatestPhp() { // Tell the user the switch is about to occur - Alert.notify(message: "alert.force_reload.title".localized, info: "alert.force_reload.info".localized) + Alert.notify( + message: "alert.force_reload.title".localized, + info: "alert.force_reload.info".localized + ) // Start switching waitAndExecute { Actions.fixMyPhp() } completion: { - Alert.notify(message: "alert.force_reload_done.title".localized, info: "alert.force_reload_done.info".localized) + Alert.notify( + message: "alert.force_reload_done.title".localized, + info: "alert.force_reload_done.info".localized + ) } } @@ -468,10 +472,8 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { } // Run composer updates - if Preferences.preferences[.autoComposerGlobalUpdateAfterSwitch] as! Bool == true { - self.updateGlobalDependencies(notify: false, completion: { success in - sendLocalNotification() - }) + if Preferences.isTrue(.autoComposerGlobalUpdateAfterSwitch) { + self.updateGlobalDependencies(notify: false, completion: { _ in sendLocalNotification() }) } else { sendLocalNotification() } diff --git a/phpmon/Domain/Preferences/Preferences.swift b/phpmon/Domain/Preferences/Preferences.swift index 45c8bff..9b2e9bd 100644 --- a/phpmon/Domain/Preferences/Preferences.swift +++ b/phpmon/Domain/Preferences/Preferences.swift @@ -66,6 +66,10 @@ class Preferences { return Self.shared.cachedPreferences } + static func isTrue(_ preference: PreferenceName) -> Bool { + return Preferences.preferences[preference] as! Bool == true + } + // MARK: - Internal Functionality static func cache() -> [PreferenceName: Any] { diff --git a/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.swift b/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.swift index 2736e08..941aef5 100644 --- a/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.swift +++ b/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.swift @@ -21,8 +21,7 @@ class CheckboxPreferenceView: NSView, XibLoadable { var preference: PreferenceName! { didSet { - let shouldDisplay = Preferences.preferences[self.preference] as! Bool == true - self.buttonCheckbox.state = shouldDisplay ? .on : .off + self.buttonCheckbox.state = Preferences.isTrue(self.preference) ? .on : .off } }