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

🏗 Allow switching silently, add operation title

This commit is contained in:
2023-05-11 20:15:53 +02:00
parent 1eeba747cf
commit 76d078735c
4 changed files with 24 additions and 7 deletions

View File

@ -10,6 +10,7 @@ import Foundation
class HomebrewOperation: BrewCommand { class HomebrewOperation: BrewCommand {
let title: String
let installing: [BrewFormula] let installing: [BrewFormula]
let upgrading: [BrewFormula] let upgrading: [BrewFormula]
let phpGuard: PhpGuard 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). Each version that is installed will need to be checked afterwards (if it is OK).
*/ */
public init( public init(
title: String,
upgrading: [BrewFormula], upgrading: [BrewFormula],
installing: [BrewFormula] installing: [BrewFormula]
) { ) {
self.title = title
self.installing = installing self.installing = installing
self.upgrading = upgrading self.upgrading = upgrading
self.phpGuard = PhpGuard() self.phpGuard = PhpGuard()
@ -112,7 +114,7 @@ class HomebrewOperation: BrewCommand {
} }
if let (number, text) = self.reportInstallationProgress(text) { 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) withTimeout: .minutes(15)
@ -127,7 +129,7 @@ class HomebrewOperation: BrewCommand {
private func completedOperations(_ onProgress: @escaping (BrewCommandProgress) -> Void) async { private func completedOperations(_ onProgress: @escaping (BrewCommandProgress) -> Void) async {
// Reload and restart PHP versions // 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 // Check which version of PHP are now installed
await PhpEnv.detectPhpVersions() 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 a PHP version was active prior to running the operations, attempt to restore it
if let version = phpGuard.currentVersion { if let version = phpGuard.currentVersion {
#warning("This should be happening silently") await MainMenu.shared.switchToAnyPhpVersion(version, silently: true)
await MainMenu.shared.switchToAnyPhpVersion(version)
} }
// Let the UI know that the installation has been completed // Let the UI know that the installation has been completed
onProgress(.create( onProgress(.create(
value: 1, value: 1,
title: "Operation completed", title: "Operation completed!",
description: "The installation has succeeded." description: "The installation has succeeded."
)) ))
} }

View File

@ -255,7 +255,10 @@ extension MainMenu {
self.switchToPhpVersion(sender.version) 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) { if PhpEnv.shared.availablePhpVersions.contains(version) {
Task { MainMenu.shared.switchToPhpVersion(version) } Task { MainMenu.shared.switchToPhpVersion(version) }
} else { } else {

View File

@ -114,6 +114,11 @@ extension MainMenu {
} }
@MainActor private func notifyAboutVersionChange(to version: String) { @MainActor private func notifyAboutVersionChange(to version: String) {
if shouldSwitchSilently {
shouldSwitchSilently = false
return
}
LocalNotification.send( LocalNotification.send(
title: String(format: "notification.version_changed_title".localized, version), title: String(format: "notification.version_changed_title".localized, version),
subtitle: String(format: "notification.version_changed_desc".localized, version), subtitle: String(format: "notification.version_changed_desc".localized, version),

View File

@ -26,6 +26,14 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
withLength: NSStatusItem.variableLength 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 // MARK: - UI related
/** /**