diff --git a/phpmon/Domain/Integrations/Homebrew/Commands/HomebrewOperation.swift b/phpmon/Domain/Integrations/Homebrew/Commands/HomebrewOperation.swift index 60389c1..2535d1a 100644 --- a/phpmon/Domain/Integrations/Homebrew/Commands/HomebrewOperation.swift +++ b/phpmon/Domain/Integrations/Homebrew/Commands/HomebrewOperation.swift @@ -10,6 +10,7 @@ import Foundation class HomebrewOperation: BrewCommand { + let title: String let installing: [BrewFormula] let upgrading: [BrewFormula] let phpGuard: PhpGuard @@ -21,10 +22,11 @@ class HomebrewOperation: BrewCommand { Each version that is installed will need to be checked afterwards (if it is OK). */ public init( + title: String, upgrading: [BrewFormula], installing: [BrewFormula] ) { - + self.title = title self.installing = installing self.upgrading = upgrading self.phpGuard = PhpGuard() @@ -112,7 +114,7 @@ class HomebrewOperation: BrewCommand { } if let (number, text) = self.reportInstallationProgress(text) { - onProgress(.create(value: number, title: "Running operations", description: text)) + onProgress(.create(value: number, title: self.title, description: text)) } }, withTimeout: .minutes(15) @@ -127,7 +129,7 @@ class HomebrewOperation: BrewCommand { private func completedOperations(_ onProgress: @escaping (BrewCommandProgress) -> Void) async { // Reload and restart PHP versions - onProgress(.create(value: 0.95, title: "Running operations", description: "Reloading PHP versions...")) + onProgress(.create(value: 0.95, title: self.title, description: "Reloading PHP versions...")) // Check which version of PHP are now installed await PhpEnv.detectPhpVersions() @@ -137,14 +139,13 @@ class HomebrewOperation: BrewCommand { // If a PHP version was active prior to running the operations, attempt to restore it if let version = phpGuard.currentVersion { - #warning("This should be happening silently") - await MainMenu.shared.switchToAnyPhpVersion(version) + await MainMenu.shared.switchToAnyPhpVersion(version, silently: true) } // Let the UI know that the installation has been completed onProgress(.create( value: 1, - title: "Operation completed", + title: "Operation completed!", description: "The installation has succeeded." )) } diff --git a/phpmon/Domain/Menu/MainMenu+Actions.swift b/phpmon/Domain/Menu/MainMenu+Actions.swift index 2cbcdef..444b14b 100644 --- a/phpmon/Domain/Menu/MainMenu+Actions.swift +++ b/phpmon/Domain/Menu/MainMenu+Actions.swift @@ -255,7 +255,10 @@ extension MainMenu { self.switchToPhpVersion(sender.version) } - public func switchToAnyPhpVersion(_ version: String) { + public func switchToAnyPhpVersion(_ version: String, silently: Bool = false) { + if silently { + MainMenu.shared.shouldSwitchSilently = true + } if PhpEnv.shared.availablePhpVersions.contains(version) { Task { MainMenu.shared.switchToPhpVersion(version) } } else { diff --git a/phpmon/Domain/Menu/MainMenu+Switcher.swift b/phpmon/Domain/Menu/MainMenu+Switcher.swift index c4485b5..a14f5d1 100644 --- a/phpmon/Domain/Menu/MainMenu+Switcher.swift +++ b/phpmon/Domain/Menu/MainMenu+Switcher.swift @@ -114,6 +114,11 @@ extension MainMenu { } @MainActor private func notifyAboutVersionChange(to version: String) { + if shouldSwitchSilently { + shouldSwitchSilently = false + return + } + LocalNotification.send( title: String(format: "notification.version_changed_title".localized, version), subtitle: String(format: "notification.version_changed_desc".localized, version), diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index f73e900..4d91c5b 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -26,6 +26,14 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate withLength: NSStatusItem.variableLength ) + // MARK: - State Variables + + /** + You can instruct the app to switch to a given PHP version silently. + That will toggle this flag to true. Upon switching, this flag will be reset. + */ + var shouldSwitchSilently: Bool = false + // MARK: - UI related /**