From cea95f4b643126b5d26bbe139b8c1478a91dd823 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Wed, 3 Jul 2019 19:13:02 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Code=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/AppDelegate.swift | 53 +++++++++++--------- phpmon/Terminal/Shell.swift | 3 +- phpmon/View Controllers/ViewController.swift | 14 ------ 3 files changed, 29 insertions(+), 41 deletions(-) diff --git a/phpmon/AppDelegate.swift b/phpmon/AppDelegate.swift index 7626071..202a7f3 100644 --- a/phpmon/AppDelegate.swift +++ b/phpmon/AppDelegate.swift @@ -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) } diff --git a/phpmon/Terminal/Shell.swift b/phpmon/Terminal/Shell.swift index fd32474..7349f61 100644 --- a/phpmon/Terminal/Shell.swift +++ b/phpmon/Terminal/Shell.swift @@ -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] diff --git a/phpmon/View Controllers/ViewController.swift b/phpmon/View Controllers/ViewController.swift index 6c7127d..52830ea 100644 --- a/phpmon/View Controllers/ViewController.swift +++ b/phpmon/View Controllers/ViewController.swift @@ -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. - } - } - - } -