mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 03:50:08 +02:00
✨ Allows quitting via menu bar item
This commit is contained in:
@ -13,6 +13,7 @@
|
|||||||
C41C1B3E22B0098000E7CF16 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C41C1B3C22B0098000E7CF16 /* Main.storyboard */; };
|
C41C1B3E22B0098000E7CF16 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C41C1B3C22B0098000E7CF16 /* Main.storyboard */; };
|
||||||
C41C1B4722B009A400E7CF16 /* Shell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B4622B009A400E7CF16 /* Shell.swift */; };
|
C41C1B4722B009A400E7CF16 /* Shell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B4622B009A400E7CF16 /* Shell.swift */; };
|
||||||
C41C1B4922B00A9800E7CF16 /* ImageGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B4822B00A9800E7CF16 /* ImageGenerator.swift */; };
|
C41C1B4922B00A9800E7CF16 /* ImageGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B4822B00A9800E7CF16 /* ImageGenerator.swift */; };
|
||||||
|
C41C1B4B22B019FF00E7CF16 /* PhpVersionExtractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B4A22B019FF00E7CF16 /* PhpVersionExtractor.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
@ -25,6 +26,7 @@
|
|||||||
C41C1B4022B0098000E7CF16 /* phpmon.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = phpmon.entitlements; sourceTree = "<group>"; };
|
C41C1B4022B0098000E7CF16 /* phpmon.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = phpmon.entitlements; sourceTree = "<group>"; };
|
||||||
C41C1B4622B009A400E7CF16 /* Shell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shell.swift; sourceTree = "<group>"; };
|
C41C1B4622B009A400E7CF16 /* Shell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shell.swift; sourceTree = "<group>"; };
|
||||||
C41C1B4822B00A9800E7CF16 /* ImageGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageGenerator.swift; sourceTree = "<group>"; };
|
C41C1B4822B00A9800E7CF16 /* ImageGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageGenerator.swift; sourceTree = "<group>"; };
|
||||||
|
C41C1B4A22B019FF00E7CF16 /* PhpVersionExtractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhpVersionExtractor.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@ -65,6 +67,7 @@
|
|||||||
C41C1B4022B0098000E7CF16 /* phpmon.entitlements */,
|
C41C1B4022B0098000E7CF16 /* phpmon.entitlements */,
|
||||||
C41C1B4622B009A400E7CF16 /* Shell.swift */,
|
C41C1B4622B009A400E7CF16 /* Shell.swift */,
|
||||||
C41C1B4822B00A9800E7CF16 /* ImageGenerator.swift */,
|
C41C1B4822B00A9800E7CF16 /* ImageGenerator.swift */,
|
||||||
|
C41C1B4A22B019FF00E7CF16 /* PhpVersionExtractor.swift */,
|
||||||
);
|
);
|
||||||
path = phpmon;
|
path = phpmon;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -143,6 +146,7 @@
|
|||||||
C41C1B4922B00A9800E7CF16 /* ImageGenerator.swift in Sources */,
|
C41C1B4922B00A9800E7CF16 /* ImageGenerator.swift in Sources */,
|
||||||
C41C1B3922B0097F00E7CF16 /* ViewController.swift in Sources */,
|
C41C1B3922B0097F00E7CF16 /* ViewController.swift in Sources */,
|
||||||
C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */,
|
C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */,
|
||||||
|
C41C1B4B22B019FF00E7CF16 /* PhpVersionExtractor.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,7 @@ import Cocoa
|
|||||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
|
|
||||||
var timer: Timer?
|
var timer: Timer?
|
||||||
|
var version: PhpVersionExtractor? = nil
|
||||||
|
|
||||||
let statusItem = NSStatusBar.system.statusItem(
|
let statusItem = NSStatusBar.system.statusItem(
|
||||||
withLength: 40
|
withLength: 40
|
||||||
@ -37,8 +38,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc func updatePhpVersionInStatusBar() {
|
@objc func updatePhpVersionInStatusBar() {
|
||||||
let version = Shell.extractPhpVersion()
|
self.version = PhpVersionExtractor()
|
||||||
self.setStatusBarImage(version: version)
|
self.setStatusBarImage(version: self.version!.short)
|
||||||
|
self.updateMenu()
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateMenu() {
|
||||||
|
let menu = NSMenu()
|
||||||
|
var string = "We are not sure what version of PHP you are running."
|
||||||
|
if (version != nil) {
|
||||||
|
string = "You are running PHP \(version!.long)"
|
||||||
|
}
|
||||||
|
menu.addItem(NSMenuItem(title: string, action: nil, keyEquivalent: ""))
|
||||||
|
menu.addItem(NSMenuItem.separator())
|
||||||
|
menu.addItem(NSMenuItem(title: "Quit phpmon", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q"))
|
||||||
|
statusItem.menu = menu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
29
phpmon/PhpVersionExtractor.swift
Normal file
29
phpmon/PhpVersionExtractor.swift
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// PhpVersionExtractor.swift
|
||||||
|
// phpmon
|
||||||
|
//
|
||||||
|
// Created by Nico Verbruggen on 11/06/2019.
|
||||||
|
// Copyright © 2019 Nico Verbruggen. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
class PhpVersionExtractor {
|
||||||
|
|
||||||
|
var short : String = "???"
|
||||||
|
var long : String = "???"
|
||||||
|
|
||||||
|
init() {
|
||||||
|
// Get the info about the PHP installation
|
||||||
|
let output = Shell.execute(command: "php -v")
|
||||||
|
// Get everything before "(cli)" (PHP X.X.X (cli) ...)
|
||||||
|
var version = output!.components(separatedBy: " (cli)")[0]
|
||||||
|
// Strip away the text before the version number
|
||||||
|
version = version.components(separatedBy: "PHP ")[1]
|
||||||
|
self.long = version
|
||||||
|
// Next up, let's strip away the minor version number
|
||||||
|
let segments = version.components(separatedBy: ".")
|
||||||
|
// Get the first two elements
|
||||||
|
self.short = segments[0...1].joined(separator: ".")
|
||||||
|
}
|
||||||
|
}
|
@ -24,18 +24,4 @@ class Shell {
|
|||||||
|
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func extractPhpVersion() -> String
|
|
||||||
{
|
|
||||||
// Get the info about the PHP installation
|
|
||||||
let output = self.execute(command: "php -v")
|
|
||||||
// Get everything before "(cli)" (PHP X.X.X (cli) ...)
|
|
||||||
var version = output!.components(separatedBy: " (cli)")[0]
|
|
||||||
// Strip away the text before the version number
|
|
||||||
version = version.components(separatedBy: "PHP ")[1]
|
|
||||||
// Next up, let's strip away the minor version number
|
|
||||||
let segments = version.components(separatedBy: ".")
|
|
||||||
// Get the first two elements
|
|
||||||
return segments[0...1].joined(separator: ".")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user