1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-09 12:43:01 +02:00

🔥 Performance improvements, memory deallocation

This commit is contained in:
2019-07-09 19:15:42 +02:00
parent 2025c951e8
commit af55e7fabc
4 changed files with 23 additions and 18 deletions

View File

@@ -9,7 +9,7 @@
import Cocoa import Cocoa
@NSApplicationMain @NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate { class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
// MARK: - Variables // MARK: - Variables
@@ -78,9 +78,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
if (self.version != nil) { if (self.version != nil) {
// Actions // Actions
menu.addItem(NSMenuItem.separator()) menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: "Open php.ini in Finder", action: #selector(self.openActiveConfigFolder), keyEquivalent: "")) menu.addItem(NSMenuItem(title: "PHP configuration file (php.ini)", action: #selector(self.openActiveConfigFolder), keyEquivalent: ""))
// OPTIONAL
// menu.addItem(NSMenuItem(title: "Restart PHP \(self.version!.short) service", action: #selector(self.restartPhp), keyEquivalent: ""))
} }
menu.addItem(NSMenuItem.separator()) menu.addItem(NSMenuItem.separator())
if (self.availablePhpVersions.count > 0 && !self.busy) { 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(title: "Switching PHP versions...", action: nil, keyEquivalent: ""))
menu.addItem(NSMenuItem.separator()) menu.addItem(NSMenuItem.separator())
} }
// TODO: Enable when implementation is complete menu.addItem(NSMenuItem(title: "View Shell Output", action: #selector(self.openOutput), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "View terminal output", action: #selector(self.openOutput), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "About phpmon", action: #selector(self.openAbout), keyEquivalent: "")) menu.addItem(NSMenuItem(title: "About phpmon", action: #selector(self.openAbout), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Quit phpmon", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")) menu.addItem(NSMenuItem(title: "Quit phpmon", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q"))
DispatchQueue.main.async { DispatchQueue.main.async {
@@ -117,19 +114,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
Shell.shared.delegate = vc Shell.shared.delegate = vc
let window = NSWindow(contentViewController: vc) let window = NSWindow(contentViewController: vc)
window.title = "Terminal Output" window.title = "Terminal Output"
window.delegate = self
self.windowController = NSWindowController(window: window) self.windowController = NSWindowController(window: window)
} }
self.windowController!.showWindow(self) self.windowController!.showWindow(self)
NSApp.activate(ignoringOtherApps: true) NSApp.activate(ignoringOtherApps: true)
// TODO: Send window to front (if possible)
} }
@objc func updatePhpVersionInStatusBar() { @objc func updatePhpVersionInStatusBar() {
self.version = PhpVersion() self.version = PhpVersion()
if (Shell.shared.history.count > 0) {
_ = Shell.shared.history.popLast()
}
if (self.busy) { if (self.busy) {
DispatchQueue.main.async { DispatchQueue.main.async {
self.setStatusBar(image: NSImage(named: NSImage.Name("StatusBarIcon"))!) 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
}
} }

View File

@@ -11,17 +11,17 @@ import AppKit
class Services { class Services {
public static func mysqlIsRunning() -> Bool { 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 != "") return (running != "")
} }
public static func nginxIsRunning() -> Bool { 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 != "") return (running != "")
} }
public static func detectPhpVersions() -> [String] { 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") var versions = files.components(separatedBy: "\n")
// Remove all empty strings // Remove all empty strings
versions.removeAll { (string) -> Bool in versions.removeAll { (string) -> Bool in
@@ -37,20 +37,20 @@ class Services {
public static func switchToPhpVersion(version: String, availableVersions: [String]) { public static func switchToPhpVersion(version: String, availableVersions: [String]) {
availableVersions.forEach { (version) in availableVersions.forEach { (version) in
Shell.shared.run( "brew unlink php@\(version)") Shell.shared.run("brew unlink php@\(version)")
} }
if (availableVersions.contains("7.3")) { 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) { if (version == Constants.LatestPhpVersion) {
Shell.shared.run( "valet use php") Shell.shared.run( "valet use php")
} else { } else {
Shell.shared.run( "valet use php@\(version)") Shell.shared.run("valet use php@\(version)")
} }
} }
} }
public static func restartPhp(version: String) { 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) { public static func openPhpConfigFolder(version: String) {

View File

@@ -60,6 +60,9 @@ class Shell {
let historyItem = ShellHistoryItem(command: command, output: output) let historyItem = ShellHistoryItem(command: command, output: output)
history.append(historyItem) history.append(historyItem)
// Keep the last 100 items
history = history.suffix(100)
print(history.count)
delegate?.didCompleteCommand(historyItem: historyItem) delegate?.didCompleteCommand(historyItem: historyItem)
return output return output

View File

@@ -52,4 +52,8 @@ class LogViewController: NSViewController, ShellDelegate {
@IBAction func pressed(_ sender: Any) { @IBAction func pressed(_ sender: Any) {
self.view.window?.windowController?.close() self.view.window?.windowController?.close()
} }
deinit {
print("VC deallocated")
}
} }