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

Add preference to disable integrations

I like the idea of the exposed phpmon:// protocol, but for those who
care about security it should be possible to disable the integrations.
This commit is contained in:
2022-01-29 12:52:33 +01:00
parent 8e61aaacde
commit 2ffe90948e
4 changed files with 22 additions and 2 deletions

View File

@ -22,6 +22,11 @@ extension AppDelegate {
*/ */
func application(_ application: NSApplication, open urls: [URL]) { func application(_ application: NSApplication, open urls: [URL]) {
if !Preferences.isEnabled(.allowProtocolForIntegrations) {
Log.info("Acting on commands via phpmon:// has been disabled.")
return
}
guard let url = urls.first else { return } guard let url = urls.first else { return }
self.interpretCommand( self.interpretCommand(

View File

@ -15,6 +15,7 @@ enum PreferenceName: String {
case fullPhpVersionDynamicIcon = "full_php_in_menu_bar" case fullPhpVersionDynamicIcon = "full_php_in_menu_bar"
case autoServiceRestartAfterExtensionToggle = "auto_restart_after_extension_toggle" case autoServiceRestartAfterExtensionToggle = "auto_restart_after_extension_toggle"
case autoComposerGlobalUpdateAfterSwitch = "auto_composer_global_update_after_switch" case autoComposerGlobalUpdateAfterSwitch = "auto_composer_global_update_after_switch"
case allowProtocolForIntegrations = "allow_protocol_for_integrations"
case globalHotkey = "global_hotkey" case globalHotkey = "global_hotkey"
} }
@ -53,12 +54,14 @@ class Preferences {
PreferenceName.shouldDisplayPhpHintInIcon.rawValue: true, PreferenceName.shouldDisplayPhpHintInIcon.rawValue: true,
PreferenceName.fullPhpVersionDynamicIcon.rawValue: false, PreferenceName.fullPhpVersionDynamicIcon.rawValue: false,
PreferenceName.autoServiceRestartAfterExtensionToggle.rawValue: true, PreferenceName.autoServiceRestartAfterExtensionToggle.rawValue: true,
PreferenceName.autoComposerGlobalUpdateAfterSwitch.rawValue: false PreferenceName.autoComposerGlobalUpdateAfterSwitch.rawValue: false,
PreferenceName.allowProtocolForIntegrations.rawValue: true,
]) ])
if UserDefaults.standard.bool(forKey: PreferenceName.wasLaunchedBefore.rawValue) { if UserDefaults.standard.bool(forKey: PreferenceName.wasLaunchedBefore.rawValue) {
return return
} }
Log.info("Saving first-time preferences!") Log.info("Saving first-time preferences!")
UserDefaults.standard.setValue(true, forKey: PreferenceName.wasLaunchedBefore.rawValue) UserDefaults.standard.setValue(true, forKey: PreferenceName.wasLaunchedBefore.rawValue)
UserDefaults.standard.synchronize() UserDefaults.standard.synchronize()
@ -96,6 +99,7 @@ class Preferences {
.fullPhpVersionDynamicIcon: UserDefaults.standard.bool(forKey: PreferenceName.fullPhpVersionDynamicIcon.rawValue) as Any, .fullPhpVersionDynamicIcon: UserDefaults.standard.bool(forKey: PreferenceName.fullPhpVersionDynamicIcon.rawValue) as Any,
.autoServiceRestartAfterExtensionToggle: UserDefaults.standard.bool(forKey: PreferenceName.autoServiceRestartAfterExtensionToggle.rawValue) as Any, .autoServiceRestartAfterExtensionToggle: UserDefaults.standard.bool(forKey: PreferenceName.autoServiceRestartAfterExtensionToggle.rawValue) as Any,
.autoComposerGlobalUpdateAfterSwitch: UserDefaults.standard.bool(forKey: PreferenceName.autoComposerGlobalUpdateAfterSwitch.rawValue) as Any, .autoComposerGlobalUpdateAfterSwitch: UserDefaults.standard.bool(forKey: PreferenceName.autoComposerGlobalUpdateAfterSwitch.rawValue) as Any,
.allowProtocolForIntegrations: UserDefaults.standard.bool(forKey: PreferenceName.allowProtocolForIntegrations.rawValue) as Any,
// Part 2: Always Strings // Part 2: Always Strings
.globalHotkey: UserDefaults.standard.string(forKey: PreferenceName.globalHotkey.rawValue) as Any, .globalHotkey: UserDefaults.standard.string(forKey: PreferenceName.globalHotkey.rawValue) as Any,

View File

@ -94,7 +94,14 @@ class PrefsVC: NSViewController {
sectionText: "prefs.global_shortcut".localized, sectionText: "prefs.global_shortcut".localized,
descriptionText: "prefs.shortcut_desc".localized, descriptionText: "prefs.shortcut_desc".localized,
self self
) ),
CheckboxPreferenceView.make(
sectionText: "prefs.integrations".localized,
descriptionText: "prefs.open_protocol_desc".localized,
checkboxText: "prefs.open_protocol_title".localized,
preference: .allowProtocolForIntegrations,
action: {}
),
].forEach({ self.stackView.addArrangedSubview($0) }) ].forEach({ self.stackView.addArrangedSubview($0) })
} }

View File

@ -131,6 +131,7 @@
"prefs.info_density" = "Info density:"; "prefs.info_density" = "Info density:";
"prefs.services" = "Services:"; "prefs.services" = "Services:";
"prefs.switcher" = "Switcher:"; "prefs.switcher" = "Switcher:";
"prefs.integrations" = "Integrations:";
"prefs.auto_restart_services_title" = "Auto-restart PHP-FPM"; "prefs.auto_restart_services_title" = "Auto-restart PHP-FPM";
"prefs.auto_restart_services_desc" = "When checked, will automatically restart PHP-FPM when you check or uncheck an extension. Slightly slower when enabled, but this applies the extension change immediately for all sites you're serving, no need to restart PHP-FPM manually."; "prefs.auto_restart_services_desc" = "When checked, will automatically restart PHP-FPM when you check or uncheck an extension. Slightly slower when enabled, but this applies the extension change immediately for all sites you're serving, no need to restart PHP-FPM manually.";
@ -147,6 +148,9 @@
"prefs.auto_composer_update_title" = "Automatically update global dependencies"; "prefs.auto_composer_update_title" = "Automatically update global dependencies";
"prefs.auto_composer_update_desc" = "When checked, will automatically ask Composer to run `composer global update` whenever you switch between different PHP versions. You will be able to see what changes are being made, or should this fail."; "prefs.auto_composer_update_desc" = "When checked, will automatically ask Composer to run `composer global update` whenever you switch between different PHP versions. You will be able to see what changes are being made, or should this fail.";
"prefs.open_protocol_title" = "Allow third-party integrations";
"prefs.open_protocol_desc" = "When checked, this will allow the interaction with third party utilities to work (e.g. Alfred, Raycast). If you disable this, PHP Monitor will still receive the commands, but will not act upon them.";
"prefs.shortcut_set" = "Set global shortcut"; "prefs.shortcut_set" = "Set global shortcut";
"prefs.shortcut_listening" = "<listening for keypress>"; "prefs.shortcut_listening" = "<listening for keypress>";
"prefs.shortcut_clear" = "Clear"; "prefs.shortcut_clear" = "Clear";