diff --git a/phpmon/Domain/App/Startup.swift b/phpmon/Domain/App/Startup.swift index 35ac141c..fd2670b4 100644 --- a/phpmon/Domain/App/Startup.swift +++ b/phpmon/Domain/App/Startup.swift @@ -201,23 +201,26 @@ class Startup { // ================================================================================= // Determine that Valet works correctly (no issues in platform detected) // ================================================================================= + /* EnvironmentCheck( command: { - let output = valet("--version", sudo: false) - return output.contains("Composer detected issues in your platform") + return valet("--version", sudo: false) + .contains("Composer detected issues in your platform") }, name: "`no global composer issues", titleText: "startup.errors.global_composer_platform_issues.title".localized, subtitleText: "startup.errors.global_composer_platform_issues.subtitle".localized, descriptionText: "startup.errors.global_composer_platform_issues.desc".localized ), + */ // ================================================================================= // Determine the Valet version and ensure it isn't unknown. // ================================================================================= EnvironmentCheck( command: { - Valet.shared.version = VersionExtractor.from(valet("--version", sudo: false)) - return Valet.shared.version == nil + let output = valet("--version", sudo: false) + Valet.shared.version = VersionExtractor.from(output) + return Valet.shared.version == nil && output.contains("Laravel Valet") }, name: "`valet --version` was loaded", titleText: "startup.errors.valet_version_unknown.title".localized, diff --git a/phpmon/Domain/Integrations/Valet/Valet.swift b/phpmon/Domain/Integrations/Valet/Valet.swift index 172dded2..6aaafeab 100644 --- a/phpmon/Domain/Integrations/Valet/Valet.swift +++ b/phpmon/Domain/Integrations/Valet/Valet.swift @@ -183,6 +183,11 @@ class Valet { } } + public func hasPlatformIssues() -> Bool { + return valet("--version", sudo: false) + .contains("Composer detected issues in your platform") + } + /** Returns a count of how many sites are linked and parked. */ diff --git a/phpmon/Domain/Menu/MainMenu+Switcher.swift b/phpmon/Domain/Menu/MainMenu+Switcher.swift index 2f412492..6680d2d4 100644 --- a/phpmon/Domain/Menu/MainMenu+Switcher.swift +++ b/phpmon/Domain/Menu/MainMenu+Switcher.swift @@ -39,11 +39,16 @@ extension MainMenu { self.notifyAboutVersionChange(to: version) } ) - } else { self.notifyAboutVersionChange(to: version) } + // Check if Valet still works correctly + if Valet.shared.hasPlatformIssues() { + Log.info("Composer platform issue(s) detected.") + self.suggestFixMyComposer() + } + // Update stats Stats.incrementSuccessfulSwitchCount() Stats.evaluateSponsorMessageShouldBeDisplayed() @@ -65,6 +70,24 @@ extension MainMenu { } } + private func suggestFixMyComposer() { + BetterAlert().withInformation( + title: "alert.global_composer_platform_issues.title".localized, + subtitle: "alert.global_composer_platform_issues.subtitle".localized, + description: "alert.global_composer_platform_issues.desc".localized + ) + .withPrimary(text: "alert.global_composer_platform_issues.buttons.update".localized, action: { alert in + alert.close(with: .OK) + self.updateGlobalComposerDependencies() + }) + .withSecondary(text: "", action: nil) + .withTertiary(text: "alert.global_composer_platform_issues.buttons.quit".localized, action: { alert in + alert.close(with: .OK) + self.terminateApp() + }) + .show() + } + private func reloadDomainListData() { if let window = App.shared.domainListWindowController { DispatchQueue.main.async { diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index 8a25c45d..8b3738c6 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -388,6 +388,13 @@ You can do this by running `composer global update` in your terminal. After that "alert.php_switch_unavailable.info" = "Please make sure PHP %@ is installed and you can switch to it in the dropdown. Currently supported versions include PHP: %@."; "alert.php_switch_unavailable.ok" = "OK"; +// Composer issues +"alert.global_composer_platform_issues.title" = "Composer detected issues in your platform"; +"alert.global_composer_platform_issues.subtitle" = "The version of PHP you switched to is too old for the global Composer dependencies you have installed. These dependencies will need to be updated."; +"alert.global_composer_platform_issues.desc" = "The easiest way to prevent this issue from occurring in the future is to switch to the oldest PHP version you have installed and to run `composer global update` again. \n\nAlternatively, you can choose the 'Automatically update global dependencies' option in Preferences to avoid this issue as well."; +"alert.global_composer_platform_issues.buttons.update" = "Update Global Dependencies"; +"alert.global_composer_platform_issues.buttons.quit" = "Quit PHP Monitor"; + // Revert "alert.revert_description.title" = "Revert Configuration?"; "alert.revert_description.subtitle" = "PHP Monitor can revert to the previous configuration that was active. Here's what will be applied: \n\n%@";