1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

🐛 Fix async issue when PHP Guard reset kicks in

Whenever PHP Guard is used to reset the PHP version when a different PHP
version is installed using the PHP Version Manager, it would previously
kick its version switching process off asynchronously as a separate task
which meant that the app would go into "ready" state too soon. Now this
is considered a blocking task that the app will wait for (async) before
turning the app back into its "ready" state again.
This commit is contained in:
2023-05-24 18:59:44 +02:00
parent 7f4c6878e4
commit a3368effec
3 changed files with 30 additions and 2 deletions

View File

@ -147,7 +147,7 @@ class InstallAndUpgradeCommand: BrewCommand {
// If a PHP version was active prior to running the operations, attempt to restore it
if let version = phpGuard.currentVersion {
await MainMenu.shared.switchToAnyPhpVersion(version, silently: true)
await MainMenu.shared.switchToPhpVersionAndWait(version, silently: true)
}
// Also rebuild the content of the main menu

View File

@ -273,6 +273,30 @@ extension MainMenu {
}
}
func switchToPhpVersionAndWait(_ version: String, silently: Bool = false) async {
if silently {
MainMenu.shared.shouldSwitchSilently = true
}
if !PhpEnvironments.shared.availablePhpVersions.contains(version) {
Log.warn("This PHP version is currently unavailable, not switching!")
return
}
setBusyImage()
PhpEnvironments.shared.isBusy = true
PhpEnvironments.shared.delegate = self
PhpEnvironments.shared.delegate?.switcherDidStartSwitching(to: version)
updatePhpVersionInStatusBar()
rebuild()
await PhpEnvironments.switcher.performSwitch(to: version)
PhpEnvironments.shared.currentInstall = ActivePhpInstallation()
App.shared.handlePhpConfigWatcher()
PhpEnvironments.shared.delegate?.switcherDidCompleteSwitch(to: version)
}
@objc func switchToPhpVersion(_ version: String) {
setBusyImage()
PhpEnvironments.shared.isBusy = true

View File

@ -197,12 +197,16 @@ struct PhpFormulaeView: View {
self.status.description = progress.description
self.status.busy = progress.value != 1
// Whenever a key step is finished, refresh the PHP versions
if progress.value == 1 {
self.setBusyStatus(false)
await self.handler.refreshPhpVersions(loadOutdated: false)
}
}
}
// Finally, after completing the command, also refresh PHP versions
await self.handler.refreshPhpVersions(loadOutdated: false)
// and mark the app as no longer busy
self.setBusyStatus(false)
} catch let error {
let error = error as! BrewCommandError
let messages = error.log.suffix(2).joined(separator: "\n")