From 2ffe90948e0cf37d1a3ac4309f7b5baa625f2be6 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Sat, 29 Jan 2022 12:52:33 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20preference=20to=20disable=20i?= =?UTF-8?q?ntegrations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I like the idea of the exposed phpmon:// protocol, but for those who care about security it should be possible to disable the integrations. --- phpmon/Domain/Core/AppDelegate+InterApp.swift | 5 +++++ phpmon/Domain/Preferences/Preferences.swift | 6 +++++- phpmon/Domain/Preferences/PrefsVC.swift | 9 ++++++++- phpmon/Localizable.strings | 4 ++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/phpmon/Domain/Core/AppDelegate+InterApp.swift b/phpmon/Domain/Core/AppDelegate+InterApp.swift index fa7dc4a..60bc11a 100644 --- a/phpmon/Domain/Core/AppDelegate+InterApp.swift +++ b/phpmon/Domain/Core/AppDelegate+InterApp.swift @@ -22,6 +22,11 @@ extension AppDelegate { */ 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 } self.interpretCommand( diff --git a/phpmon/Domain/Preferences/Preferences.swift b/phpmon/Domain/Preferences/Preferences.swift index 2b411e4..93ee9ab 100644 --- a/phpmon/Domain/Preferences/Preferences.swift +++ b/phpmon/Domain/Preferences/Preferences.swift @@ -15,6 +15,7 @@ enum PreferenceName: String { case fullPhpVersionDynamicIcon = "full_php_in_menu_bar" case autoServiceRestartAfterExtensionToggle = "auto_restart_after_extension_toggle" case autoComposerGlobalUpdateAfterSwitch = "auto_composer_global_update_after_switch" + case allowProtocolForIntegrations = "allow_protocol_for_integrations" case globalHotkey = "global_hotkey" } @@ -53,12 +54,14 @@ class Preferences { PreferenceName.shouldDisplayPhpHintInIcon.rawValue: true, PreferenceName.fullPhpVersionDynamicIcon.rawValue: false, PreferenceName.autoServiceRestartAfterExtensionToggle.rawValue: true, - PreferenceName.autoComposerGlobalUpdateAfterSwitch.rawValue: false + PreferenceName.autoComposerGlobalUpdateAfterSwitch.rawValue: false, + PreferenceName.allowProtocolForIntegrations.rawValue: true, ]) if UserDefaults.standard.bool(forKey: PreferenceName.wasLaunchedBefore.rawValue) { return } + Log.info("Saving first-time preferences!") UserDefaults.standard.setValue(true, forKey: PreferenceName.wasLaunchedBefore.rawValue) UserDefaults.standard.synchronize() @@ -96,6 +99,7 @@ class Preferences { .fullPhpVersionDynamicIcon: UserDefaults.standard.bool(forKey: PreferenceName.fullPhpVersionDynamicIcon.rawValue) as Any, .autoServiceRestartAfterExtensionToggle: UserDefaults.standard.bool(forKey: PreferenceName.autoServiceRestartAfterExtensionToggle.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 .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 04c9fb9..13b1e9d 100644 --- a/phpmon/Domain/Preferences/PrefsVC.swift +++ b/phpmon/Domain/Preferences/PrefsVC.swift @@ -94,7 +94,14 @@ class PrefsVC: NSViewController { sectionText: "prefs.global_shortcut".localized, descriptionText: "prefs.shortcut_desc".localized, 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) }) } diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index 9eeca45..a938af9 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -131,6 +131,7 @@ "prefs.info_density" = "Info density:"; "prefs.services" = "Services:"; "prefs.switcher" = "Switcher:"; +"prefs.integrations" = "Integrations:"; "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."; @@ -146,6 +147,9 @@ "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.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_listening" = "";