Skip to content

Commit

Permalink
🐛 Check for platform issue after switch (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoverbruggen committed Jun 29, 2022
1 parent 6fbbd49 commit 5c3e856
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
11 changes: 7 additions & 4 deletions phpmon/Domain/App/Startup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions phpmon/Domain/Integrations/Valet/Valet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
25 changes: 24 additions & 1 deletion phpmon/Domain/Menu/MainMenu+Switcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions phpmon/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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%@";
Expand Down

0 comments on commit 5c3e856

Please sign in to comment.