mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 12:00:09 +02:00
✨ Switch Xdebug mode
This commit is contained in:
@ -15,7 +15,11 @@ class Xdebug {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static var mode: String {
|
public static var mode: String {
|
||||||
return Command.execute(path: Paths.php, arguments: ["-r", "echo ini_get('xdebug.mode');"])
|
guard let file = PhpEnv.shared.getConfigFile(forKey: "xdebug.mode") else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return file.get(for: "xdebug.mode") ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
public static var modes: [String] {
|
public static var modes: [String] {
|
||||||
|
@ -174,4 +174,14 @@ class PhpEnv {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the configuration file instance that is used for a specific config value.
|
||||||
|
You can then use the configuration file instance to change values.
|
||||||
|
*/
|
||||||
|
public func getConfigFile(forKey key: String) -> PhpConfigurationFile? {
|
||||||
|
return PhpEnv.phpInstall.iniFiles
|
||||||
|
.reversed()
|
||||||
|
.first(where: { $0.has(key: key) })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,6 +244,23 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
|
|||||||
|
|
||||||
@objc func toggleXdebugMode(sender: XdebugMenuItem) {
|
@objc func toggleXdebugMode(sender: XdebugMenuItem) {
|
||||||
Log.info("Switching Xdebug to mode: \(sender.mode)")
|
Log.info("Switching Xdebug to mode: \(sender.mode)")
|
||||||
|
|
||||||
|
guard let file = PhpEnv.shared.getConfigFile(forKey: "xdebug.mode") else {
|
||||||
|
Log.info("xdebug.mode could not be found in any .ini file, aborting.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
// Replace the xdebug mode
|
||||||
|
try file.replace(key: "xdebug.mode", value: sender.mode)
|
||||||
|
// Refresh the menu
|
||||||
|
Log.perf("Refreshing menu...")
|
||||||
|
MainMenu.shared.rebuild()
|
||||||
|
// Restart PHP-FPM
|
||||||
|
restartPhpFpm()
|
||||||
|
} catch {
|
||||||
|
Log.err("There was an issue replacing `xdebug.mode` in \(file.filePath)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func toggleExtension(sender: ExtensionMenuItem) {
|
@objc func toggleExtension(sender: ExtensionMenuItem) {
|
||||||
|
@ -68,7 +68,7 @@ class StatusMenu: NSMenu {
|
|||||||
|
|
||||||
self.addItem(NSMenuItem.separator())
|
self.addItem(NSMenuItem.separator())
|
||||||
|
|
||||||
// self.addXdebugMenuItem()
|
self.addXdebugMenuItem()
|
||||||
|
|
||||||
self.addFirstAidAndServicesMenuItems()
|
self.addFirstAidAndServicesMenuItems()
|
||||||
}
|
}
|
||||||
|
@ -11,16 +11,16 @@ import Foundation
|
|||||||
extension App {
|
extension App {
|
||||||
|
|
||||||
func startWatcher(_ url: URL) {
|
func startWatcher(_ url: URL) {
|
||||||
Log.info("No watcher currently active...")
|
Log.perf("No watcher currently active...")
|
||||||
self.watcher = PhpConfigWatcher(for: url)
|
self.watcher = PhpConfigWatcher(for: url)
|
||||||
|
|
||||||
self.watcher.didChange = { url in
|
self.watcher.didChange = { url in
|
||||||
Log.info("Something has changed in: \(url)")
|
Log.perf("Something has changed in: \(url)")
|
||||||
|
|
||||||
// Check if the watcher has last updated the menu less than 0.75s ago
|
// Check if the watcher has last updated the menu less than 0.75s ago
|
||||||
let distance = self.watcher.lastUpdate?.distance(to: Date().timeIntervalSince1970)
|
let distance = self.watcher.lastUpdate?.distance(to: Date().timeIntervalSince1970)
|
||||||
if distance == nil || distance != nil && distance! > 0.75 {
|
if distance == nil || distance != nil && distance! > 0.75 {
|
||||||
Log.info("Refreshing menu...")
|
Log.perf("Refreshing menu...")
|
||||||
MainMenu.shared.reloadPhpMonitorMenuInBackground()
|
MainMenu.shared.reloadPhpMonitorMenuInBackground()
|
||||||
self.watcher.lastUpdate = Date().timeIntervalSince1970
|
self.watcher.lastUpdate = Date().timeIntervalSince1970
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ extension App {
|
|||||||
if self.watcher.url != url || forceReload {
|
if self.watcher.url != url || forceReload {
|
||||||
self.watcher.disable()
|
self.watcher.disable()
|
||||||
self.watcher = nil
|
self.watcher = nil
|
||||||
Log.info("Watcher has stopped watching files. Starting new one...")
|
Log.perf("Watcher has stopped watching files. Starting new one...")
|
||||||
self.startWatcher(url)
|
self.startWatcher(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user