mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-04-03 01:50:09 +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:
@@ -147,7 +147,7 @@ class InstallAndUpgradeCommand: BrewCommand {
|
|||||||
|
|
||||||
// If a PHP version was active prior to running the operations, attempt to restore it
|
// If a PHP version was active prior to running the operations, attempt to restore it
|
||||||
if let version = phpGuard.currentVersion {
|
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
|
// Also rebuild the content of the main menu
|
||||||
|
|||||||
@@ -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) {
|
@objc func switchToPhpVersion(_ version: String) {
|
||||||
setBusyImage()
|
setBusyImage()
|
||||||
PhpEnvironments.shared.isBusy = true
|
PhpEnvironments.shared.isBusy = true
|
||||||
|
|||||||
@@ -197,12 +197,16 @@ struct PhpFormulaeView: View {
|
|||||||
self.status.description = progress.description
|
self.status.description = progress.description
|
||||||
self.status.busy = progress.value != 1
|
self.status.busy = progress.value != 1
|
||||||
|
|
||||||
|
// Whenever a key step is finished, refresh the PHP versions
|
||||||
if progress.value == 1 {
|
if progress.value == 1 {
|
||||||
self.setBusyStatus(false)
|
|
||||||
await self.handler.refreshPhpVersions(loadOutdated: 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 {
|
} catch let error {
|
||||||
let error = error as! BrewCommandError
|
let error = error as! BrewCommandError
|
||||||
let messages = error.log.suffix(2).joined(separator: "\n")
|
let messages = error.log.suffix(2).joined(separator: "\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user