mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-09 12:43:01 +02:00
✨ Code cleanup
This commit is contained in:
@@ -11,14 +11,15 @@ import Cocoa
|
|||||||
@NSApplicationMain
|
@NSApplicationMain
|
||||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
|
|
||||||
let statusItem = NSStatusBar.system.statusItem(
|
// MARK: - Variables
|
||||||
withLength: 32
|
|
||||||
)
|
|
||||||
|
|
||||||
|
let statusItem = NSStatusBar.system.statusItem(withLength: 32)
|
||||||
var timer: Timer?
|
var timer: Timer?
|
||||||
var version: PhpVersion? = nil
|
var version: PhpVersion? = nil
|
||||||
var availablePhpVersions : [String] = []
|
var availablePhpVersions : [String] = []
|
||||||
var busy: Bool = false
|
var busy: Bool = false
|
||||||
|
|
||||||
|
// MARK: - Lifecycle
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||||
// Start with the icon
|
// Start with the icon
|
||||||
@@ -41,6 +42,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applicationWillTerminate(_ aNotification: Notification) {
|
||||||
|
// Insert code here to tear down your application
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - UI related
|
||||||
|
|
||||||
func setStatusBarImage(version: String) {
|
func setStatusBarImage(version: String) {
|
||||||
self.setStatusBar(image: ImageGenerator.generateImageForStatusBar(width: 32.0, text: version))
|
self.setStatusBar(image: ImageGenerator.generateImageForStatusBar(width: 32.0, text: version))
|
||||||
}
|
}
|
||||||
@@ -52,24 +59,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationWillTerminate(_ aNotification: Notification) {
|
|
||||||
// Insert code here to tear down your application
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc func updatePhpVersionInStatusBar() {
|
|
||||||
self.version = PhpVersion()
|
|
||||||
if (self.busy) {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.setStatusBar(image: NSImage(named: NSImage.Name("StatusBarIcon"))!)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.setStatusBarImage(version: self.version!.short)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.updateMenu()
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateMenu() {
|
func updateMenu() {
|
||||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||||
let menu = NSMenu()
|
let menu = NSMenu()
|
||||||
@@ -109,18 +98,32 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Callable via Obj-C (#selector)
|
||||||
|
|
||||||
|
@objc func updatePhpVersionInStatusBar() {
|
||||||
|
self.version = PhpVersion()
|
||||||
|
if (self.busy) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.setStatusBar(image: NSImage(named: NSImage.Name("StatusBarIcon"))!)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.setStatusBarImage(version: self.version!.short)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.updateMenu()
|
||||||
|
}
|
||||||
|
|
||||||
@objc public func openAbout() {
|
@objc public func openAbout() {
|
||||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||||
NSApplication.shared.orderFrontStandardAboutPanel()
|
NSApplication.shared.orderFrontStandardAboutPanel()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func openActiveConfigFolder()
|
@objc public func openActiveConfigFolder() {
|
||||||
{
|
|
||||||
Services.openPhpConfigFolder(version: self.version!.short)
|
Services.openPhpConfigFolder(version: self.version!.short)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func restartPhp()
|
@objc public func restartPhp() {
|
||||||
{
|
|
||||||
Services.restartPhp(version: self.version!.short)
|
Services.restartPhp(version: self.version!.short)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,8 +10,7 @@ import Cocoa
|
|||||||
|
|
||||||
class Shell {
|
class Shell {
|
||||||
|
|
||||||
public static func execute(command: String) -> String
|
public static func execute(command: String) -> String {
|
||||||
{
|
|
||||||
let task = Process()
|
let task = Process()
|
||||||
task.launchPath = "/bin/bash"
|
task.launchPath = "/bin/bash"
|
||||||
task.arguments = ["--login", "-c", command]
|
task.arguments = ["--login", "-c", command]
|
||||||
|
@@ -10,18 +10,4 @@ import Cocoa
|
|||||||
|
|
||||||
class ViewController: NSViewController {
|
class ViewController: NSViewController {
|
||||||
|
|
||||||
override func viewDidLoad() {
|
|
||||||
super.viewDidLoad()
|
|
||||||
|
|
||||||
// Do any additional setup after loading the view.
|
|
||||||
}
|
|
||||||
|
|
||||||
override var representedObject: Any? {
|
|
||||||
didSet {
|
|
||||||
// Update the view, if already loaded.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user