mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 03:50:08 +02:00
👌 Sync global & window busy indicator
This commit is contained in:
@ -40,7 +40,14 @@ class PhpEnv {
|
||||
static let shared = PhpEnv()
|
||||
|
||||
/** Whether the switcher is busy performing any actions. */
|
||||
var isBusy: Bool = false
|
||||
var isBusy: Bool = false {
|
||||
didSet {
|
||||
Task { @MainActor in
|
||||
MainMenu.shared.setBusyImage()
|
||||
MainMenu.shared.rebuild()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** All versions of PHP that are currently supported. */
|
||||
var availablePhpVersions: [String] = []
|
||||
|
@ -150,7 +150,7 @@ struct PhpFormulaeView: View {
|
||||
let command = InstallPhpVersionCommand(formula: formula.name)
|
||||
|
||||
do {
|
||||
PhpEnv.shared.isBusy = true
|
||||
self.setBusyStatus(true)
|
||||
try await command.execute { progress in
|
||||
Task { @MainActor in
|
||||
self.status.title = progress.title
|
||||
@ -158,16 +158,13 @@ struct PhpFormulaeView: View {
|
||||
self.status.busy = progress.value != 1
|
||||
|
||||
if progress.value == 1 {
|
||||
PhpEnv.shared.isBusy = false
|
||||
self.setBusyStatus(false)
|
||||
await self.handler.refreshPhpVersions(loadOutdated: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
PhpEnv.shared.isBusy = false
|
||||
Task { @MainActor in
|
||||
self.status.busy = false
|
||||
}
|
||||
self.setBusyStatus(false)
|
||||
self.presentErrorAlert(
|
||||
title: "phpman.failures.install.title".localized,
|
||||
description: "phpman.failures.install.desc".localized(
|
||||
@ -182,7 +179,7 @@ struct PhpFormulaeView: View {
|
||||
let command = RemovePhpVersionCommand(formula: formula.name)
|
||||
|
||||
do {
|
||||
PhpEnv.shared.isBusy = true
|
||||
self.setBusyStatus(true)
|
||||
try await command.execute { progress in
|
||||
Task { @MainActor in
|
||||
self.status.title = progress.title
|
||||
@ -191,15 +188,12 @@ struct PhpFormulaeView: View {
|
||||
|
||||
if progress.value == 1 {
|
||||
await self.handler.refreshPhpVersions(loadOutdated: false)
|
||||
PhpEnv.shared.isBusy = false
|
||||
self.setBusyStatus(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
PhpEnv.shared.isBusy = false
|
||||
Task { @MainActor in
|
||||
self.status.busy = false
|
||||
}
|
||||
self.setBusyStatus(false)
|
||||
self.presentErrorAlert(
|
||||
title: "phpman.failures.uninstall.title".localized,
|
||||
description: "phpman.failures.uninstall.desc".localized(
|
||||
@ -210,6 +204,22 @@ struct PhpFormulaeView: View {
|
||||
}
|
||||
}
|
||||
|
||||
public func setBusyStatus(_ busy: Bool) {
|
||||
PhpEnv.shared.isBusy = busy
|
||||
if busy {
|
||||
Task { @MainActor in
|
||||
MainMenu.shared.setBusyImage()
|
||||
MainMenu.shared.rebuild()
|
||||
self.status.busy = busy
|
||||
}
|
||||
} else {
|
||||
Task { @MainActor in
|
||||
MainMenu.shared.updatePhpVersionInStatusBar()
|
||||
self.status.busy = busy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func presentErrorAlert(title: String, description: String, button: String) {
|
||||
Alert.confirm(
|
||||
onWindow: App.shared.versionManagerWindowController!.window!,
|
||||
|
Reference in New Issue
Block a user