diff --git a/phpmon/Domain/App/AppDelegate+InterApp.swift b/phpmon/Domain/App/AppDelegate+InterApp.swift index f606d80d..fc51c16a 100644 --- a/phpmon/Domain/App/AppDelegate+InterApp.swift +++ b/phpmon/Domain/App/AppDelegate+InterApp.swift @@ -8,22 +8,30 @@ import Cocoa import Foundation +import NVAlert extension AppDelegate { /** This is an entry point for future development for integrating with the PHP Monitor application URL. You can use the `phpmon://` protocol to communicate with the app. - + At this time you can trigger the site list using Alfred (or some other application) by opening the following URL: `phpmon://list`. - + Please note that PHP Monitor needs to be running in the background for this to work. */ @MainActor func application(_ application: NSApplication, open urls: [URL]) { if !Preferences.isEnabled(.allowProtocolForIntegrations) { - Log.info("Acting on commands via phpmon:// has been disabled.") - return + if UserDefaults.standard.bool(forKey: PersistentAppState.didPromptForIntegrations.rawValue) { + Log.info("Acting on commands via phpmon:// has been disabled.") + return + } + + Log.info("Acting on commands via phpmon:// has been disabled. Prompting user...") + if !promptToEnableIntegrations() { + return + } } guard let url = urls.first else { return } @@ -34,6 +42,26 @@ extension AppDelegate { ) } + private func promptToEnableIntegrations() -> Bool { + UserDefaults.standard.set(true, forKey: PersistentAppState.didPromptForIntegrations.rawValue) + UserDefaults.standard.synchronize() + + if !NVAlert() + .withInformation( + title: "alert.enable_integrations.title".localized, + subtitle: "alert.enable_integrations.subtitle".localized, + description: "alert.enable_integrations.desc".localized + ) + .withPrimary(text: "alert.enable_integrations.ok".localized) + .withSecondary(text: "alert.enable_integrations.cancel".localized) + .didSelectPrimary(urgency: .bringToFront) { + return false + } + + Preferences.update(.allowProtocolForIntegrations, value: true) + return true + } + private func interpretCommand(_ command: String, commands: [InterApp.Action]) { commands.forEach { action in if command.starts(with: action.command) { diff --git a/phpmon/Domain/Preferences/PreferenceName.swift b/phpmon/Domain/Preferences/PreferenceName.swift index f3201fff..6d72dbe9 100644 --- a/phpmon/Domain/Preferences/PreferenceName.swift +++ b/phpmon/Domain/Preferences/PreferenceName.swift @@ -111,6 +111,7 @@ enum PersistentAppState: String { case lastAutomaticUpdateCheck = "last_automatic_update_check" case userFavorites = "user_favorites" case updateCheckFailureCount = "update_check_failure_count" + case didPromptForIntegrations = "did_prompt_for_integrations" } /** diff --git a/phpmon/Domain/Preferences/Preferences.swift b/phpmon/Domain/Preferences/Preferences.swift index 98c28fdb..b89aa438 100644 --- a/phpmon/Domain/Preferences/Preferences.swift +++ b/phpmon/Domain/Preferences/Preferences.swift @@ -62,7 +62,7 @@ class Preferences { /// Preferences: General PreferenceName.autoServiceRestartAfterExtensionToggle.rawValue: true, PreferenceName.autoComposerGlobalUpdateAfterSwitch.rawValue: false, - PreferenceName.allowProtocolForIntegrations.rawValue: true, + PreferenceName.allowProtocolForIntegrations.rawValue: false, PreferenceName.automaticBackgroundUpdateCheck.rawValue: true, PreferenceName.showPhpDoctorSuggestions.rawValue: true, PreferenceName.languageOverride.rawValue: "", diff --git a/phpmon/en.lproj/Localizable.strings b/phpmon/en.lproj/Localizable.strings index fa9152d6..e619c7d6 100644 --- a/phpmon/en.lproj/Localizable.strings +++ b/phpmon/en.lproj/Localizable.strings @@ -949,3 +949,11 @@ PHP Monitor will tell Valet to unsecure and re-secure all expired domains for yo ➡️ If the crash keeps happening at a specific point in time, you may want to check GitHub's issue tracker to see if a fix is not in the works. If the app keeps crashing prior to initialization, you may need to update PHP Monitor manually."; "crash_reporter.send_report" = "Send Report"; "crash_reporter.do_not_send" = "Don't Send"; + +// THIRD-PARTY INTEGRATIONS + +"alert.enable_integrations.title" = "An external application is trying to communicate with PHP Monitor"; +"alert.enable_integrations.subtitle" = "Do you want to allow third-party integrations (like Alfred or Raycast) to control PHP Monitor via the phpmon:// protocol?\n\nThis prompt appeared because PHP Monitor just received an external command. If you triggered this from a third-party app like Alfred or Raycast, it is safe to allow this.\n\nYou can change this setting later in Preferences."; +"alert.enable_integrations.desc" = "If you did not trigger this via Alfred or Raycast, there may be another application trying to control PHP Monitor. In that case I recommend checking what could be causing this and keeping this integration turned off for security reasons."; +"alert.enable_integrations.ok" = "Allow Integrations"; +"alert.enable_integrations.cancel" = "Don't Allow";