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:
@ -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."
|
||||
))
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user