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

Also show full PHP version in dropdown (#53)

This commit is contained in:
2021-11-25 18:41:21 +01:00
parent 34900f929f
commit 2d6ca0f841
6 changed files with 43 additions and 6 deletions

View File

@ -30,7 +30,7 @@ _You may need to update your Valet installation to keep everything working if a
## 🚀 How to install
You can install via Homebrew, or may download the latest [release](https://github.com/nicoverbruggen/phpmon/releases).
You can install via Homebrew (recommended), or may download the latest release on GitHub.
To install via Homebrew, run:

View File

@ -32,6 +32,27 @@ class Actions {
return versionsOnly
}
/**
This method extracts the PHP full version number after finding the php installation folders.
To be refactored at some later point, I'd like to cache the `PhpInstallation` objects instead of just the version number at some point.
*/
public static func extractPhpLongVersions() -> [String: String]
{
var mappedVersions: [String: String] = [:]
App.shared.availablePhpVersions.forEach { version in
let phpConfigExecutablePath = "\(Paths.optPath)/php@\(version)/bin/php-config"
var longVersion = version
if Shell.fileExists(phpConfigExecutablePath) {
longVersion = Command.execute(
path: phpConfigExecutablePath,
arguments: ["--version"]
)
}
mappedVersions[version] = longVersion
}
return mappedVersions
}
/**
Extracts valid PHP versions from an array of strings.
This array of strings is usually retrieved from `grep`.

View File

@ -49,6 +49,11 @@ class App {
*/
var availablePhpVersions : [String] = []
/**
Cached information about the PHP installations; contains only the full version number at this point.
*/
var cachedPhpVersionNumbers : [String: String] = [:]
/**
The timer that will periodically fetch the PHP version that is currently active.
*/

View File

@ -42,6 +42,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
*/
private func onEnvironmentPass() {
App.shared.availablePhpVersions = Actions.detectPhpVersions()
App.shared.cachedPhpVersionNumbers = Actions.extractPhpLongVersions()
updatePhpVersionInStatusBar()
let installation = App.phpInstall!

View File

@ -42,15 +42,24 @@ class StatusMenu : NSMenu {
private func addSwitchToPhpMenuItems() {
var shortcutKey = 1
for index in (0..<App.shared.availablePhpVersions.count).reversed() {
let version = App.shared.availablePhpVersions[index]
// Get the short and long version
let shortVersion = App.shared.availablePhpVersions[index]
let longVersion = App.shared.cachedPhpVersionNumbers[shortVersion]!
let long = Preferences.preferences[.fullPhpVersionDynamicIcon] as! Bool
let versionString = long ? longVersion : shortVersion
let action = #selector(MainMenu.switchToPhpVersion(sender:))
let brew = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)"
let brew = (shortVersion == App.shared.brewPhpVersion) ? "php" : "php@\(shortVersion)"
let menuItem = PhpMenuItem(
title: "\("mi_php_switch".localized) \(version) (\(brew))",
action: (version == App.phpInstall?.version.short) ? nil : action, keyEquivalent: "\(shortcutKey)"
title: "\("mi_php_switch".localized) \(versionString) (\(brew))",
action: (shortVersion == App.phpInstall?.version.short) ? nil : action, keyEquivalent: "\(shortcutKey)"
)
menuItem.version = version
menuItem.version = shortVersion
shortcutKey = shortcutKey + 1
self.addItem(menuItem)
}
}

View File

@ -123,6 +123,7 @@ class PrefsVC: NSViewController {
@IBAction func toggledFullPhpVersion(_ sender: Any) {
Preferences.update(.fullPhpVersionDynamicIcon, value: buttonDisplayFullPhpVersion.state == .on)
MainMenu.shared.refreshIcon()
MainMenu.shared.update()
}
@IBAction func toggledAutoRestartServices(_ sender: Any) {