From 6aff283d08e6a95ebd66a4268b87497e9db1f363 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Wed, 22 Mar 2023 21:58:50 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Sync=20global=20&=20window=20bus?= =?UTF-8?q?y=20indicator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/Common/PHP/PHP Version/PhpEnv.swift | 9 ++++- .../SwiftUI/PhpManager/PhpFormulaeView.swift | 34 ++++++++++++------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/phpmon/Common/PHP/PHP Version/PhpEnv.swift b/phpmon/Common/PHP/PHP Version/PhpEnv.swift index d5cb0bb..a884413 100644 --- a/phpmon/Common/PHP/PHP Version/PhpEnv.swift +++ b/phpmon/Common/PHP/PHP Version/PhpEnv.swift @@ -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] = [] diff --git a/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift b/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift index cf2fa61..e438c23 100644 --- a/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift +++ b/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift @@ -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!,