diff --git a/phpmon/Domain/Core/Base.lproj/Main.storyboard b/phpmon/Domain/Core/Base.lproj/Main.storyboard index 6c9f733..280c01c 100644 --- a/phpmon/Domain/Core/Base.lproj/Main.storyboard +++ b/phpmon/Domain/Core/Base.lproj/Main.storyboard @@ -313,6 +313,10 @@ + + + + @@ -330,7 +334,7 @@ - + - + @@ -402,20 +406,20 @@ Gw - + - + - + - + @@ -429,7 +433,7 @@ Gw - + @@ -447,18 +451,18 @@ Gw - + - + - + + + + + + + + + + @@ -486,24 +508,28 @@ Gw + - + + + + @@ -516,10 +542,12 @@ Gw + + @@ -527,7 +555,7 @@ Gw - + @@ -590,13 +618,13 @@ Gw - + - + - + @@ -714,7 +742,7 @@ Gw - + diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index 1ad6479..dd9f50e 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -359,12 +359,23 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { } } - // TODO: Allow for switcher to vary? - Actions.switchToPhpVersionUsingValet( - version: sender.version, - availableVersions: App.shared.availablePhpVersions, - completed: completion - ) + if Preferences.preferences[.useInternalSwitcher] as! Bool == false { + // 1. Default switcher using Valet + // Will cause less issues, but is slower + Actions.switchToPhpVersionUsingValet( + version: sender.version, + availableVersions: App.shared.availablePhpVersions, + completed: completion + ) + } else { + // 2. Custom switcher (internal) + // Will cause more issues with Homebrew and is faster + Actions.switchToPhpVersion( + version: sender.version, + availableVersions: App.shared.availablePhpVersions, + completed: completion + ) + } } } diff --git a/phpmon/Domain/Preferences/Preferences.swift b/phpmon/Domain/Preferences/Preferences.swift index 398368b..4cb9efc 100644 --- a/phpmon/Domain/Preferences/Preferences.swift +++ b/phpmon/Domain/Preferences/Preferences.swift @@ -13,6 +13,7 @@ enum PreferenceName: String { case shouldDisplayDynamicIcon = "use_dynamic_icon" case fullPhpVersionDynamicIcon = "full_php_in_menu_bar" case autoServiceRestartAfterExtensionToggle = "auto_restart_after_extension_toggle" + case useInternalSwitcher = "use_phpmon_switcher" case globalHotkey = "global_hotkey" } @@ -45,7 +46,8 @@ class Preferences { UserDefaults.standard.register(defaults: [ PreferenceName.shouldDisplayDynamicIcon.rawValue: true, PreferenceName.fullPhpVersionDynamicIcon.rawValue: false, - PreferenceName.autoServiceRestartAfterExtensionToggle.rawValue: true + PreferenceName.autoServiceRestartAfterExtensionToggle.rawValue: true, + PreferenceName.useInternalSwitcher.rawValue: false ]) if UserDefaults.standard.bool(forKey: PreferenceName.wasLaunchedBefore.rawValue) { @@ -70,6 +72,7 @@ class Preferences { .shouldDisplayDynamicIcon: UserDefaults.standard.bool(forKey: PreferenceName.shouldDisplayDynamicIcon.rawValue) as Any, .fullPhpVersionDynamicIcon: UserDefaults.standard.bool(forKey: PreferenceName.fullPhpVersionDynamicIcon.rawValue) as Any, .autoServiceRestartAfterExtensionToggle: UserDefaults.standard.bool(forKey: PreferenceName.autoServiceRestartAfterExtensionToggle.rawValue) as Any, + .useInternalSwitcher: UserDefaults.standard.bool(forKey: PreferenceName.useInternalSwitcher.rawValue) as Any, // Part 2: Always Strings .globalHotkey: UserDefaults.standard.string(forKey: PreferenceName.globalHotkey.rawValue) as Any, diff --git a/phpmon/Domain/Preferences/PrefsVC.swift b/phpmon/Domain/Preferences/PrefsVC.swift index 6448f61..f7e8a22 100644 --- a/phpmon/Domain/Preferences/PrefsVC.swift +++ b/phpmon/Domain/Preferences/PrefsVC.swift @@ -31,6 +31,10 @@ class PrefsVC: NSViewController { @IBOutlet weak var buttonAutoRestartServices: NSButton! @IBOutlet weak var labelAutoRestartServices: NSTextField! + // Use own services + @IBOutlet weak var buttonUseInternalSwitcher: NSButton! + @IBOutlet weak var labelUseInternalSwitcher: NSTextField! + // Shortcut @IBOutlet weak var buttonSetShortcut: NSButton! @IBOutlet weak var buttonClearShortcut: NSButton! @@ -49,6 +53,7 @@ class PrefsVC: NSViewController { ) as! PrefsWC windowController.window!.title = "prefs.title".localized + windowController.window!.subtitle = "prefs.subtitle".localized windowController.window!.delegate = delegate windowController.window!.styleMask = [.titled, .closable, .miniaturizable] windowController.window!.delegate = windowController @@ -72,6 +77,7 @@ class PrefsVC: NSViewController { loadDynamicIconFromPreferences() loadFullPhpVersionFromPreferences() loadGlobalKeybindFromPreferences() + loadUseInternalSwitcherFromPreferences() } override func viewWillDisappear() { @@ -93,7 +99,11 @@ class PrefsVC: NSViewController { // Services leftLabelServices.stringValue = "prefs.services".localized buttonAutoRestartServices.title = "prefs.auto_restart_services_title".localized - labelAutoRestartServices.stringValue = "prefs_auto_restart_services_desc".localized + labelAutoRestartServices.stringValue = "prefs.auto_restart_services_desc".localized + + // Switcher + buttonUseInternalSwitcher.title = "prefs.use_internal_switcher".localized + labelUseInternalSwitcher.stringValue = "prefs.use_internal_switcher_desc".localized // Global Shortcut leftLabelGlobalShortcut.stringValue = "prefs.global_shortcut".localized @@ -122,6 +132,11 @@ class PrefsVC: NSViewController { self.buttonAutoRestartServices.state = shouldDisplay ? .on : .off } + func loadUseInternalSwitcherFromPreferences() { + let shouldDisplay = Preferences.preferences[.useInternalSwitcher] as! Bool == true + self.buttonUseInternalSwitcher.state = shouldDisplay ? .on : .off + } + // MARK: - Actions @IBAction func toggledDynamicIcon(_ sender: Any) { @@ -139,6 +154,10 @@ class PrefsVC: NSViewController { Preferences.update(.autoServiceRestartAfterExtensionToggle, value: buttonAutoRestartServices.state == .on) } + @IBAction func toggledUseInternalSwitcher(_ sender: Any) { + Preferences.update(.useInternalSwitcher, value: buttonUseInternalSwitcher.state == .on) + } + // MARK: - Shortcut Preference // Adapted from: https://dev.to/mitchartemis/creating-a-global-configurable-shortcut-for-macos-apps-in-swift-25e9 diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index ae82b11..ea884af 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -71,6 +71,7 @@ // PREFERENCES "prefs.title" = "PHP Monitor"; +"prefs.subtitle" = "Preferences"; "prefs.close" = "Close"; "prefs.global_shortcut" = "Global shortcut:"; @@ -78,13 +79,22 @@ "prefs.services" = "Services:"; "prefs.auto_restart_services_title" = "Auto-restart PHP-FPM"; -"prefs_auto_restart_services_desc" = "When checked, will automatically restart PHP-FPM when\nyou check or uncheck an extension. Slightly slower when enabled, \nbut this applies the extension change immediately for all sites \nyou're serving, no need to restart PHP-FPM manually."; +"prefs.auto_restart_services_desc" = "When checked, will automatically restart PHP-FPM when\nyou check or uncheck an extension. Slightly slower when enabled, \nbut this applies the extension change immediately for all sites \nyou're serving, no need to restart PHP-FPM manually."; "prefs.dynamic_icon_title" = "Display dynamic icon in menu bar"; "prefs.dynamic_icon_desc" = "If you uncheck this box, the truck icon will always be visible.\nIf checked, it will display the major version number of the\ncurrently linked PHP version."; "prefs.display_full_php_version" = "Display full PHP version in menu bar"; "prefs.display_full_php_version_desc" = "Display the full version instead of the major version only.\n(This may be undesirable on smaller displays,\nso this is disabled by default.)"; + +"prefs.use_internal_switcher" = "Use PHP Monitor’s own version switcher"; +"prefs.use_internal_switcher_desc" = +"By default, PHP Monitor will attempt to use Laravel Valet +in order to switch PHP versions. If you prefer a different +switcher or are having issues with `valet use php`, you may +use PHP Monitor's own switcher which is slightly faster, +but might cause issues with permissions in your Homebrew +directories, since PHP Monitor controls the services."; "prefs.shortcut_set" = "Set global shortcut"; "prefs.shortcut_listening" = "";