1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-08 04:20:07 +02:00

👌 Even more cleanup

This commit is contained in:
2022-01-03 16:09:49 +01:00
parent 8624573e74
commit 78510ea3fe
3 changed files with 14 additions and 6 deletions

View File

@ -307,7 +307,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
waitAndExecute {
sender.phpExtension?.toggle()
if Preferences.isTrue(.autoServiceRestartAfterExtensionToggle) {
if Preferences.isEnabled(.autoServiceRestartAfterExtensionToggle) {
Actions.restartPhpFpm()
}
}
@ -472,7 +472,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
}
// Run composer updates
if Preferences.isTrue(.autoComposerGlobalUpdateAfterSwitch) {
if Preferences.isEnabled(.autoComposerGlobalUpdateAfterSwitch) {
self.updateGlobalDependencies(notify: false, completion: { _ in sendLocalNotification() })
} else {
sendLocalNotification()

View File

@ -66,13 +66,21 @@ class Preferences {
return Self.shared.cachedPreferences
}
static func isTrue(_ preference: PreferenceName) -> Bool {
return Preferences.preferences[preference] as! Bool == true
/**
Determine whether a particular preference is enabled.
- Important: Requires the preference to have a corresponding boolean value, or a fatal error will be thrown.
*/
static func isEnabled(_ preference: PreferenceName) -> Bool {
if let bool = Preferences.preferences[preference] as? Bool {
return bool == true
} else {
fatalError("\(preference) is not a valid boolean preference!")
}
}
// MARK: - Internal Functionality
static func cache() -> [PreferenceName: Any] {
private static func cache() -> [PreferenceName: Any] {
return [
// Part 1: Always Booleans
.shouldDisplayDynamicIcon: UserDefaults.standard.bool(forKey: PreferenceName.shouldDisplayDynamicIcon.rawValue) as Any,

View File

@ -21,7 +21,7 @@ class CheckboxPreferenceView: NSView, XibLoadable {
var preference: PreferenceName! {
didSet {
self.buttonCheckbox.state = Preferences.isTrue(self.preference) ? .on : .off
self.buttonCheckbox.state = Preferences.isEnabled(self.preference) ? .on : .off
}
}