mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-06 19:40:08 +02:00
✨ Code cleanup
This commit is contained in:
@ -11,14 +11,15 @@ import Cocoa
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
let statusItem = NSStatusBar.system.statusItem(
|
||||
withLength: 32
|
||||
)
|
||||
// MARK: - Variables
|
||||
|
||||
let statusItem = NSStatusBar.system.statusItem(withLength: 32)
|
||||
var timer: Timer?
|
||||
var version: PhpVersion? = nil
|
||||
var availablePhpVersions : [String] = []
|
||||
var busy: Bool = false
|
||||
|
||||
// MARK: - Lifecycle
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
// 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) {
|
||||
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() {
|
||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||
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() {
|
||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||
NSApplication.shared.orderFrontStandardAboutPanel()
|
||||
}
|
||||
|
||||
@objc public func openActiveConfigFolder()
|
||||
{
|
||||
@objc public func openActiveConfigFolder() {
|
||||
Services.openPhpConfigFolder(version: self.version!.short)
|
||||
}
|
||||
|
||||
@objc public func restartPhp()
|
||||
{
|
||||
@objc public func restartPhp() {
|
||||
Services.restartPhp(version: self.version!.short)
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,7 @@ import Cocoa
|
||||
|
||||
class Shell {
|
||||
|
||||
public static func execute(command: String) -> String
|
||||
{
|
||||
public static func execute(command: String) -> String {
|
||||
let task = Process()
|
||||
task.launchPath = "/bin/bash"
|
||||
task.arguments = ["--login", "-c", command]
|
||||
|
@ -10,18 +10,4 @@ import Cocoa
|
||||
|
||||
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