diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 80a6a97..9221fca 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -2799,7 +2799,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1000; + CURRENT_PROJECT_VERSION = 1020; DEAD_CODE_STRIPPING = YES; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; @@ -2828,7 +2828,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1000; + CURRENT_PROJECT_VERSION = 1020; DEAD_CODE_STRIPPING = YES; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; @@ -3056,7 +3056,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1000; + CURRENT_PROJECT_VERSION = 1020; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; @@ -3166,7 +3166,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1000; + CURRENT_PROJECT_VERSION = 1020; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; diff --git a/phpmon/Common/PHP/PHP Version/PhpEnv.swift b/phpmon/Common/PHP/PHP Version/PhpEnv.swift index d3332c9..bbd78e8 100644 --- a/phpmon/Common/PHP/PHP Version/PhpEnv.swift +++ b/phpmon/Common/PHP/PHP Version/PhpEnv.swift @@ -172,6 +172,9 @@ class PhpEnv { public func validate(_ version: String) -> Bool { if self.currentInstall.version.short == version { Log.info("Switching to version \(version) seems to have succeeded. Validation passed.") + Log.info("Keeping track that this is the new version!") + Stats.persistCurrentGlobalPhpVersion(version: version) + return true } diff --git a/phpmon/Common/PHP/Switcher/InternalSwitcher.swift b/phpmon/Common/PHP/Switcher/InternalSwitcher.swift index d86b1a6..76669a9 100644 --- a/phpmon/Common/PHP/Switcher/InternalSwitcher.swift +++ b/phpmon/Common/PHP/Switcher/InternalSwitcher.swift @@ -51,9 +51,6 @@ class InternalSwitcher: PhpSwitcher { await brew("services restart nginx", sudo: true) Log.info("The new version(s) have been linked!") - - // Persist which formula is linked so we can check at launch - Stats.persistCurrentGlobalPhpVersion(version: PhpEnv.phpInstall.formula) }) } diff --git a/phpmon/Domain/App/InterAppHandler.swift b/phpmon/Domain/App/InterAppHandler.swift index c8bb0a5..dd2816b 100644 --- a/phpmon/Domain/App/InterAppHandler.swift +++ b/phpmon/Domain/App/InterAppHandler.swift @@ -53,19 +53,7 @@ class InterApp { Task { MainMenu.shared.openPhpInfo() } }), InterApp.Action(command: "switch/php/", action: { version in - if PhpEnv.shared.availablePhpVersions.contains(version) { - Task { MainMenu.shared.switchToPhpVersion(version) } - } else { - Task { - BetterAlert().withInformation( - title: "alert.php_switch_unavailable.title".localized, - subtitle: "alert.php_switch_unavailable.subtitle".localized(version) - ).withPrimary( - text: "alert.php_switch_unavailable.ok".localized - ).show() - } - } + Task { MainMenu.shared.switchToAnyPhpVersion(version) } }) ]} - } diff --git a/phpmon/Domain/Menu/MainMenu+Actions.swift b/phpmon/Domain/Menu/MainMenu+Actions.swift index 6cd6dda..da27abf 100644 --- a/phpmon/Domain/Menu/MainMenu+Actions.swift +++ b/phpmon/Domain/Menu/MainMenu+Actions.swift @@ -231,6 +231,21 @@ extension MainMenu { self.switchToPhpVersion(sender.version) } + public func switchToAnyPhpVersion(_ version: String) { + if PhpEnv.shared.availablePhpVersions.contains(version) { + Task { MainMenu.shared.switchToPhpVersion(version) } + } else { + Task { + BetterAlert().withInformation( + title: "alert.php_switch_unavailable.title".localized, + subtitle: "alert.php_switch_unavailable.subtitle".localized(version) + ).withPrimary( + text: "alert.php_switch_unavailable.ok".localized + ).show() + } + } + } + @objc func switchToPhpVersion(_ version: String) { setBusyImage() PhpEnv.shared.isBusy = true diff --git a/phpmon/Domain/Preferences/Stats.swift b/phpmon/Domain/Preferences/Stats.swift index 3155bd9..4ceb701 100644 --- a/phpmon/Domain/Preferences/Stats.swift +++ b/phpmon/Domain/Preferences/Stats.swift @@ -145,8 +145,6 @@ class Stats { let currentVersion = PhpEnv.phpInstall.version.short let previousVersion = Stats.lastGlobalPhpVersion - // TODO: Add a preference to disable this - // Save the PHP version that is currently in use (only if unknown) if Stats.lastGlobalPhpVersion == "" { Stats.persistCurrentGlobalPhpVersion(version: currentVersion) @@ -159,15 +157,27 @@ class Stats { BetterAlert() .withInformation( title: "startup.version_mismatch.title".localized, - subtitle: "startup.version_mismatch.subtitle".localized, - description: "startup.version_mismatch.desc".localized + subtitle: "startup.version_mismatch.subtitle".localized( + currentVersion, + previousVersion + ), + description: "startup.version_mismatch.desc".localized() ) - .withPrimary(text: "OK") - // TODO: Add secondary button to switch to that version (if possible) + .withPrimary(text: "startup.version_mismatch.button_switch_back".localized( + previousVersion + ), action: { alert in + alert.close(with: .OK) + Task { MainMenu.shared.switchToAnyPhpVersion(previousVersion) } + }) + .withTertiary(text: "startup.version_mismatch.button_stay".localized( + currentVersion + ), action: { alert in + Stats.persistCurrentGlobalPhpVersion(version: currentVersion) + alert.close(with: .OK) + }) .show() } } } } - } diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index bc1317a..7fef6f9 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -540,6 +540,13 @@ If you are seeing this message but are confused why this folder has gone missing "startup.errors.which_alias_issue.subtitle" = "It appears that there's a file in `/usr/local/bin/which`. This is usually set up by NodeJS, but `node` isn't in the PATH in `/usr/local/bin`. To fix this, keep reading."; "startup.errors.which_alias_issue.desc" = "You will need to symlink `node` into the `/usr/local/bin` directory to make sure PHP Monitor can start successfully. For more info, see: https://github.com/nicoverbruggen/phpmon/issues/174"; +// Warning about a different PHP version linked than last time +"startup.version_mismatch.title" = "Your active PHP version has changed."; +"startup.version_mismatch.subtitle" = "Since PHP Monitor was last active, your linked PHP version has been changed to PHP %@. Would you like to switch back to PHP %@, or do you want to keep using the current version?"; +"startup.version_mismatch.desc" = "PHP Monitor keeps track of which version of PHP is globally linked. The global version may have been changed due to some other program or Homebrew may have linked a different formula after upgrades."; +"startup.version_mismatch.button_switch_back" = "Switch back to PHP %@"; +"startup.version_mismatch.button_stay" = "Keep using PHP %@"; + // SPONSOR ENCOURAGEMENT "startup.sponsor_encouragement.title" = "If PHP Monitor has been useful to you or your company, please consider leaving a tip.";