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

👌 Cleanup

This commit is contained in:
2022-01-03 16:02:18 +01:00
parent dd251936b9
commit 8624573e74
4 changed files with 33 additions and 15 deletions

View File

@ -75,6 +75,19 @@ class Actions {
NSWorkspace.shared.activateFileViewerSelecting([file] as [URL]) NSWorkspace.shared.activateFileViewerSelecting([file] as [URL])
} }
// MARK: - Other Actions
public static func createTempPhpInfoFile() -> URL
{
// Write a file called `phpmon_phpinfo.php` to /tmp
try! "<?php phpinfo();".write(toFile: "/tmp/phpmon_phpinfo.php", atomically: true, encoding: .utf8)
// Tell php-cgi to run the PHP and output as an .html file
Shell.run("\(Paths.binPath)/php-cgi -q /tmp/phpmon_phpinfo.php > /tmp/phpmon_phpinfo.html")
return URL(string: "file:///private/tmp/phpmon_phpinfo.html")!
}
// MARK: - Quick Fix // MARK: - Quick Fix
/** /**

View File

@ -307,34 +307,38 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
waitAndExecute { waitAndExecute {
sender.phpExtension?.toggle() sender.phpExtension?.toggle()
if Preferences.preferences[.autoServiceRestartAfterExtensionToggle] as! Bool == true { if Preferences.isTrue(.autoServiceRestartAfterExtensionToggle) {
Actions.restartPhpFpm() Actions.restartPhpFpm()
} }
} }
} }
@objc func openPhpInfo() { @objc func openPhpInfo() {
waitAndExecute { var url: URL? = nil
// Write a file called `phpmon_phpinfo.php` to /tmp
try! "<?php phpinfo();".write(toFile: "/tmp/phpmon_phpinfo.php", atomically: true, encoding: .utf8)
// Tell php-cgi to run the PHP and output as an .html file waitAndExecute {
Shell.run("\(Paths.binPath)/php-cgi -q /tmp/phpmon_phpinfo.php > /tmp/phpmon_phpinfo.html") url = Actions.createTempPhpInfoFile()
} completion: { } completion: {
// When this has been completed, open the URL to the file in the browser // When this has been completed, open the URL to the file in the browser
NSWorkspace.shared.open(URL(string: "file:///private/tmp/phpmon_phpinfo.html")!) NSWorkspace.shared.open(url!)
} }
} }
@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
waitAndExecute { waitAndExecute {
Actions.fixMyPhp() Actions.fixMyPhp()
} completion: { } completion: {
Alert.notify(message: "alert.force_reload_done.title".localized, info: "alert.force_reload_done.info".localized) Alert.notify(
message: "alert.force_reload_done.title".localized,
info: "alert.force_reload_done.info".localized
)
} }
} }
@ -468,10 +472,8 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
} }
// Run composer updates // Run composer updates
if Preferences.preferences[.autoComposerGlobalUpdateAfterSwitch] as! Bool == true { if Preferences.isTrue(.autoComposerGlobalUpdateAfterSwitch) {
self.updateGlobalDependencies(notify: false, completion: { success in self.updateGlobalDependencies(notify: false, completion: { _ in sendLocalNotification() })
sendLocalNotification()
})
} else { } else {
sendLocalNotification() sendLocalNotification()
} }

View File

@ -66,6 +66,10 @@ class Preferences {
return Self.shared.cachedPreferences return Self.shared.cachedPreferences
} }
static func isTrue(_ preference: PreferenceName) -> Bool {
return Preferences.preferences[preference] as! Bool == true
}
// MARK: - Internal Functionality // MARK: - Internal Functionality
static func cache() -> [PreferenceName: Any] { static func cache() -> [PreferenceName: Any] {

View File

@ -21,8 +21,7 @@ class CheckboxPreferenceView: NSView, XibLoadable {
var preference: PreferenceName! { var preference: PreferenceName! {
didSet { didSet {
let shouldDisplay = Preferences.preferences[self.preference] as! Bool == true self.buttonCheckbox.state = Preferences.isTrue(self.preference) ? .on : .off
self.buttonCheckbox.state = shouldDisplay ? .on : .off
} }
} }