mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-06 19:40:08 +02:00
🔥 Performance improvements, memory deallocation
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
import Cocoa
|
||||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
|
||||
|
||||
// MARK: - Variables
|
||||
|
||||
@ -78,9 +78,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
if (self.version != nil) {
|
||||
// Actions
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
menu.addItem(NSMenuItem(title: "Open php.ini in Finder", action: #selector(self.openActiveConfigFolder), keyEquivalent: ""))
|
||||
// OPTIONAL
|
||||
// menu.addItem(NSMenuItem(title: "Restart PHP \(self.version!.short) service", action: #selector(self.restartPhp), keyEquivalent: ""))
|
||||
menu.addItem(NSMenuItem(title: "PHP configuration file (php.ini)", action: #selector(self.openActiveConfigFolder), keyEquivalent: ""))
|
||||
}
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
if (self.availablePhpVersions.count > 0 && !self.busy) {
|
||||
@ -99,8 +97,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
menu.addItem(NSMenuItem(title: "Switching PHP versions...", action: nil, keyEquivalent: ""))
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
}
|
||||
// TODO: Enable when implementation is complete
|
||||
menu.addItem(NSMenuItem(title: "View terminal output", action: #selector(self.openOutput), keyEquivalent: ""))
|
||||
menu.addItem(NSMenuItem(title: "View Shell Output", action: #selector(self.openOutput), keyEquivalent: ""))
|
||||
menu.addItem(NSMenuItem(title: "About phpmon", action: #selector(self.openAbout), keyEquivalent: ""))
|
||||
menu.addItem(NSMenuItem(title: "Quit phpmon", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q"))
|
||||
DispatchQueue.main.async {
|
||||
@ -117,19 +114,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
Shell.shared.delegate = vc
|
||||
let window = NSWindow(contentViewController: vc)
|
||||
window.title = "Terminal Output"
|
||||
window.delegate = self
|
||||
self.windowController = NSWindowController(window: window)
|
||||
}
|
||||
self.windowController!.showWindow(self)
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
|
||||
// TODO: Send window to front (if possible)
|
||||
}
|
||||
|
||||
@objc func updatePhpVersionInStatusBar() {
|
||||
self.version = PhpVersion()
|
||||
if (Shell.shared.history.count > 0) {
|
||||
_ = Shell.shared.history.popLast()
|
||||
}
|
||||
if (self.busy) {
|
||||
DispatchQueue.main.async {
|
||||
self.setStatusBar(image: NSImage(named: NSImage.Name("StatusBarIcon"))!)
|
||||
@ -176,5 +169,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func windowWillClose(_ notification: Notification) {
|
||||
self.windowController = nil
|
||||
Shell.shared.delegate = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,17 +11,17 @@ import AppKit
|
||||
|
||||
class Services {
|
||||
public static func mysqlIsRunning() -> Bool {
|
||||
let running = Shell.shared.pipe( "launchctl list | grep homebrew.mxcl.mysql")
|
||||
let running = Shell.shared.pipe("launchctl list | grep homebrew.mxcl.mysql")
|
||||
return (running != "")
|
||||
}
|
||||
|
||||
public static func nginxIsRunning() -> Bool {
|
||||
let running = Shell.shared.pipe( "launchctl list | grep homebrew.mxcl.nginx")
|
||||
let running = Shell.shared.pipe("launchctl list | grep homebrew.mxcl.nginx")
|
||||
return (running != "")
|
||||
}
|
||||
|
||||
public static func detectPhpVersions() -> [String] {
|
||||
let files = Shell.shared.pipe( "ls /usr/local/opt | grep php@")
|
||||
let files = Shell.shared.pipe("ls /usr/local/opt | grep php@")
|
||||
var versions = files.components(separatedBy: "\n")
|
||||
// Remove all empty strings
|
||||
versions.removeAll { (string) -> Bool in
|
||||
@ -37,20 +37,20 @@ class Services {
|
||||
|
||||
public static func switchToPhpVersion(version: String, availableVersions: [String]) {
|
||||
availableVersions.forEach { (version) in
|
||||
Shell.shared.run( "brew unlink php@\(version)")
|
||||
Shell.shared.run("brew unlink php@\(version)")
|
||||
}
|
||||
if (availableVersions.contains("7.3")) {
|
||||
Shell.shared.run( "brew link php@7.3")
|
||||
Shell.shared.run("brew link php@7.3")
|
||||
if (version == Constants.LatestPhpVersion) {
|
||||
Shell.shared.run( "valet use php")
|
||||
} else {
|
||||
Shell.shared.run( "valet use php@\(version)")
|
||||
Shell.shared.run("valet use php@\(version)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static func restartPhp(version: String) {
|
||||
Shell.shared.run( "brew services restart php@\(version)")
|
||||
Shell.shared.run("brew services restart php@\(version)")
|
||||
}
|
||||
|
||||
public static func openPhpConfigFolder(version: String) {
|
||||
|
@ -60,6 +60,9 @@ class Shell {
|
||||
|
||||
let historyItem = ShellHistoryItem(command: command, output: output)
|
||||
history.append(historyItem)
|
||||
// Keep the last 100 items
|
||||
history = history.suffix(100)
|
||||
print(history.count)
|
||||
delegate?.didCompleteCommand(historyItem: historyItem)
|
||||
|
||||
return output
|
||||
|
@ -52,4 +52,8 @@ class LogViewController: NSViewController, ShellDelegate {
|
||||
@IBAction func pressed(_ sender: Any) {
|
||||
self.view.window?.windowController?.close()
|
||||
}
|
||||
|
||||
deinit {
|
||||
print("VC deallocated")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user