1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-08 04:20:07 +02:00

👌 Multiple trailing closures

This commit is contained in:
2021-03-19 15:44:26 +01:00
parent 8a47cfd5f1
commit 0ad6e5cb1c

View File

@ -136,7 +136,7 @@ class MainMenu: NSObject, NSWindowDelegate {
- Parameter execute: Callback of the work that needs to happen. - Parameter execute: Callback of the work that needs to happen.
- Parameter completion: Callback that is fired when the work is done. - Parameter completion: Callback that is fired when the work is done.
*/ */
private func waitAndExecute(_ execute: @escaping () -> Void, _ completion: @escaping () -> Void = {}) private func waitAndExecute(_ execute: @escaping () -> Void, completion: @escaping () -> Void = {})
{ {
App.shared.busy = true App.shared.busy = true
self.setBusyImage() self.setBusyImage()
@ -183,53 +183,51 @@ class MainMenu: NSObject, NSWindowDelegate {
} }
@objc func restartAllServices() { @objc func restartAllServices() {
self.waitAndExecute({ self.waitAndExecute {
Actions.restartDnsMasq() Actions.restartDnsMasq()
Actions.restartPhpFpm() Actions.restartPhpFpm()
Actions.restartNginx() Actions.restartNginx()
}) }
} }
@objc func restartNginx() { @objc func restartNginx() {
self.waitAndExecute({ self.waitAndExecute {
Actions.restartNginx() Actions.restartNginx()
}) }
} }
@objc func restartDnsMasq() { @objc func restartDnsMasq() {
self.waitAndExecute({ self.waitAndExecute {
Actions.restartDnsMasq() Actions.restartDnsMasq()
}) }
} }
@objc func toggleExtension(sender: ExtensionMenuItem) { @objc func toggleExtension(sender: ExtensionMenuItem) {
self.waitAndExecute({ self.waitAndExecute {
// Toggle that extension // Toggle that extension
print("Toggling extension '\(sender.phpExtension!.name)'") print("Toggling extension '\(sender.phpExtension!.name)'")
sender.phpExtension?.toggle() sender.phpExtension?.toggle()
}) }
} }
@objc func openPhpInfo() { @objc func openPhpInfo() {
self.waitAndExecute({ self.waitAndExecute {
try! "<?php phpinfo();".write(toFile: "/tmp/phpmon_phpinfo.php", atomically: true, encoding: .utf8) try! "<?php phpinfo();".write(toFile: "/tmp/phpmon_phpinfo.php", atomically: true, encoding: .utf8)
Shell.run("\(Paths.binPath)/php-cgi -q /tmp/phpmon_phpinfo.php > /tmp/phpmon_phpinfo.html") Shell.run("\(Paths.binPath)/php-cgi -q /tmp/phpmon_phpinfo.php > /tmp/phpmon_phpinfo.html")
}, { } completion: {
NSWorkspace.shared.open(URL(string: "file:///private/tmp/phpmon_phpinfo.html")!) NSWorkspace.shared.open(URL(string: "file:///private/tmp/phpmon_phpinfo.html")!)
}) }
} }
@objc func forceRestartLatestPhp() { @objc func forceRestartLatestPhp() {
// Tell the user the switch is about to occur // Tell the user the switch is about to occur
Alert.notify(message: "alert.force_reload.title".localized, info: "alert.force_reload.info".localized) Alert.notify(message: "alert.force_reload.title".localized, info: "alert.force_reload.info".localized)
// Start switching // Start switching
self.waitAndExecute( self.waitAndExecute {
{ Actions.fixMyPhp() }, Actions.fixMyPhp()
{ Alert.notify( } completion: {
message: "alert.force_reload_done.title".localized, Alert.notify(message: "alert.force_reload_done.title".localized, info: "alert.force_reload_done.info".localized)
info: "alert.force_reload_done.info".localized }
) }
)
} }
@objc func openActiveConfigFolder() { @objc func openActiveConfigFolder() {