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

🏗 WIP: Cleanup

This commit is contained in:
2023-05-11 22:08:42 +02:00
parent 104f3a7d8c
commit 67ec63212c
4 changed files with 19 additions and 29 deletions

View File

@@ -145,6 +145,9 @@ class InstallAndUpgradeCommand: BrewCommand {
await MainMenu.shared.switchToAnyPhpVersion(version, silently: true) await MainMenu.shared.switchToAnyPhpVersion(version, silently: true)
} }
// Also rebuild the content of the main menu
await MainMenu.shared.rebuild()
// 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,

View File

@@ -62,7 +62,8 @@ class Valet {
} }
lazy var installed: Bool = { lazy var installed: Bool = {
return FileSystem.fileExists(Paths.binPath.appending("/valet")) && FileSystem.anyExists("~/.config/valet") return FileSystem.fileExists(Paths.binPath.appending("/valet"))
&& FileSystem.anyExists("~/.config/valet")
}() }()
/** /**

View File

@@ -8,6 +8,7 @@
import Cocoa import Cocoa
class StatusMenu: NSMenu { class StatusMenu: NSMenu {
// swiftlint:disable cyclomatic_complexity
func addMenuItems() { func addMenuItems() {
addPhpVersionMenuItems() addPhpVersionMenuItems()
addItem(NSMenuItem.separator()) addItem(NSMenuItem.separator())

View File

@@ -14,42 +14,27 @@ extension App {
let notifier = FSNotifier( let notifier = FSNotifier(
for: URL(fileURLWithPath: Paths.binPath), for: URL(fileURLWithPath: Paths.binPath),
eventMask: .all, eventMask: .all,
onChange: { onChange: { Task { await self.onHomebrewPhpModification() } }
Task { await self.onHomebrewPhpModification() }
// Removing requires termination and then removing reference
// self.watchers[.homebrewBinaries]?.terminate()
// self.watchers[.homebrewBinaries] = nil
}
) )
App.shared.watchers[.homebrewBinaries] = notifier App.shared.watchers[.homebrewBinaries] = notifier
} }
public func destroyHomebrewWatchers() {
// Removing requires termination and then removing reference
self.watchers[.homebrewBinaries]?.terminate()
self.watchers[.homebrewBinaries] = nil
}
public func onHomebrewPhpModification() async { public func onHomebrewPhpModification() async {
let previous = PhpEnv.shared.currentInstall?.version.text // let previous = PhpEnv.shared.currentInstall?.version.text
Log.info("Something changed in the Homebrew binary directory...") Log.info("Something changed in the Homebrew binary directory...")
await PhpEnv.detectPhpVersions() await PhpEnv.detectPhpVersions()
await MainMenu.shared.refreshActiveInstallation() await MainMenu.shared.refreshActiveInstallation()
let new = PhpEnv.shared.currentInstall?.version.text // let new = PhpEnv.shared.currentInstall?.version.text
if previous != new {
#warning("Notifications should be opt-in and are currently disabled") // TODO:
Log.info("The PHP version has changed, new version is now: \(new ?? "unlinked")") // Check if the new and previous version are different
/* // if so, we can show a notification if needed
// These notifications will cause duplicate notifications if using the switcher
if new != nil {
LocalNotification.send(
title: "Globally linked PHP version has changed!",
subtitle: "PHP \(new!) is now active.",
preference: nil
)
} else {
LocalNotification.send(
title: "Globally linked PHP version has changed!",
subtitle: "PHP is now unlinked.",
preference: nil
)
}
*/
}
} }
} }