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

♻️ Use Localizable.strings

This commit is contained in:
2020-05-16 23:32:34 +02:00
parent f2d01748be
commit 1c455ea05a
6 changed files with 83 additions and 54 deletions

View File

@ -16,6 +16,7 @@
C41C1B4D22B0215A00E7CF16 /* Actions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B4C22B0215A00E7CF16 /* Actions.swift */; };
C42295DD2358D02000E263B2 /* Command.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42295DC2358D02000E263B2 /* Command.swift */; };
C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C46FA23E246C358E00944F05 /* StringExtension.swift */; };
C473319F2470923A009A0597 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C473319E2470923A009A0597 /* Localizable.strings */; };
C476FF9822B0DD830098105B /* Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = C476FF9722B0DD830098105B /* Alert.swift */; };
C4811D2422D70A4700B5F6B3 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2322D70A4700B5F6B3 /* App.swift */; };
C4811D2A22D70F9A00B5F6B3 /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */; };
@ -37,6 +38,7 @@
C41C1B4C22B0215A00E7CF16 /* Actions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Actions.swift; sourceTree = "<group>"; };
C42295DC2358D02000E263B2 /* Command.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Command.swift; sourceTree = "<group>"; };
C46FA23E246C358E00944F05 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
C473319E2470923A009A0597 /* Localizable.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; };
C476FF9722B0DD830098105B /* Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alert.swift; sourceTree = "<group>"; };
C4811D2322D70A4700B5F6B3 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenu.swift; sourceTree = "<group>"; };
@ -86,6 +88,7 @@
C41C1B3F22B0098000E7CF16 /* Info.plist */,
C41C1B4022B0098000E7CF16 /* phpmon.entitlements */,
C41C1B3A22B0098000E7CF16 /* Assets.xcassets */,
C473319E2470923A009A0597 /* Localizable.strings */,
);
path = phpmon;
sourceTree = "<group>";
@ -206,6 +209,7 @@
files = (
C41C1B3B22B0098000E7CF16 /* Assets.xcassets in Resources */,
C41C1B3E22B0098000E7CF16 /* Main.storyboard in Resources */,
C473319F2470923A009A0597 /* Localizable.strings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -65,6 +65,11 @@ class Actions {
}
}
public static func openGenericPhpConfigFolder() {
let files = [NSURL(fileURLWithPath: "/usr/local/etc/php")];
NSWorkspace.shared.activateFileViewerSelecting(files as [URL])
}
public static func openPhpConfigFolder(version: String) {
let files = [NSURL(fileURLWithPath: "/usr/local/etc/php/\(version)/php.ini")];
NSWorkspace.shared.activateFileViewerSelecting(files as [URL])
@ -75,7 +80,7 @@ class Actions {
NSWorkspace.shared.activateFileViewerSelecting(files as [URL])
}
public static func XdebugFound(_ version: String) -> Bool {
public static func didFindXdebug(_ version: String) -> Bool {
let command = """
grep -q 'zend_extension="xdebug.so"' /usr/local/etc/php/\(version)/php.ini; [ $? -eq 0 ] && echo "YES" || echo "NO"
"""
@ -83,7 +88,7 @@ class Actions {
return (output == "YES")
}
public static func XdebugEnabled(_ version: String) -> Bool {
public static func didEnableXdebug(_ version: String) -> Bool {
let command = """
grep -q '; zend_extension="xdebug.so"' /usr/local/etc/php/\(version)/php.ini; [ $? -eq 0 ] && echo "YES" || echo "NO"
"""
@ -96,7 +101,7 @@ class Actions {
var command = """
sed -i '' 's/; zend_extension="xdebug.so"/zend_extension="xdebug.so"/g' /usr/local/etc/php/\(version!)/php.ini
"""
if (self.XdebugEnabled(version!)) {
if (self.didEnableXdebug(version!)) {
command = """
sed -i '' 's/zend_extension="xdebug.so"/; zend_extension="xdebug.so"/g' /usr/local/etc/php/\(version!)/php.ini
"""

View File

@ -38,9 +38,9 @@ class PhpVersion {
self.short = segments[0...1].joined(separator: ".")
// Load xdebug support
self.xdebugFound = Actions.XdebugFound(self.short)
self.xdebugFound = Actions.didFindXdebug(self.short)
if (self.xdebugFound) {
self.xdebugEnabled = Actions.XdebugEnabled(self.short)
self.xdebugEnabled = Actions.didEnableXdebug(self.short)
}
self.error = false;

View File

@ -9,6 +9,11 @@
import Foundation
extension String {
var localized: String {
return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "")
}
func countInstances(of stringToFind: String) -> Int {
if (stringToFind.isEmpty) {
return 0

View File

@ -0,0 +1,17 @@
/*
Strings.strings
PHP Monitor
Created by Nico Verbruggen on 16/05/2020.
Copyright © 2020 Nico Verbruggen. All rights reserved.
*/
// ALERTS
// Force Reload Started
"alert.force_reload.title" = "PHP Monitor will force reload the latest version of PHP";
"alert.force_reload.info" = "This can take a while. You'll get another alert when the force reload has completed.";
// Force Reload Done
"alert.force_reload_done.title" = "PHP has been force reloaded";
"alert.force_reload_done.info" = "All appropriate services have been restarted, and the latest version of PHP is now active. You can now try switching to another version of PHP.";

View File

@ -69,7 +69,7 @@ class MainMenu: NSObject, NSWindowDelegate {
menu.addItem(NSMenuItem(title: "Active Services", action: nil, keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Restart php-fpm service", action: #selector(self.restartPhpFpm), keyEquivalent: "f"))
menu.addItem(NSMenuItem(title: "Restart nginx service", action: #selector(self.restartNginx), keyEquivalent: "n"))
menu.addItem(NSMenuItem(title: "Force load latest PHP version", action: #selector(self.fixMyPhp), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Force load latest PHP version", action: #selector(self.forceRestartLatestPhp), keyEquivalent: ""))
menu.addItem(NSMenuItem.separator())
}
if (App.shared.busy) {
@ -129,6 +129,24 @@ class MainMenu: NSObject, NSWindowDelegate {
}
}
// MARK: - Invokable Logic
private func waitAndExecute(_ execute: @escaping () -> Void, _ completion: @escaping () -> Void = {})
{
App.shared.busy = true
self.setBusyImage()
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
self.update()
execute()
App.shared.busy = false
DispatchQueue.main.async {
self.updatePhpVersionInStatusBar()
self.update()
completion()
}
}
}
// MARK: - Callable via Obj-C (#selector)
@objc func updatePhpVersionInStatusBar() {
@ -151,21 +169,6 @@ class MainMenu: NSObject, NSWindowDelegate {
}
}
private func waitAndExecute(_ execute: @escaping () -> Void)
{
App.shared.busy = true
self.setBusyImage()
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
self.update()
execute()
App.shared.busy = false
DispatchQueue.main.async {
self.updatePhpVersionInStatusBar()
self.update()
}
}
}
@objc public func restartPhpFpm() {
self.waitAndExecute({
Actions.restartPhpFpm()
@ -178,13 +181,34 @@ class MainMenu: NSObject, NSWindowDelegate {
})
}
@objc public func openAbout() {
NSApplication.shared.activate(ignoringOtherApps: true)
NSApplication.shared.orderFrontStandardAboutPanel()
@objc public func toggleXdebug() {
self.waitAndExecute({
Actions.toggleXdebug()
})
}
@objc public func forceRestartLatestPhp() {
Alert.present(
messageText: "alert.force_reload.title".localized,
informativeText: "alert.force_reload.info".localized
)
self.waitAndExecute({ Actions.fixMyPhp() }, {
Alert.present(
messageText: "alert.force_reload_done.title".localized,
informativeText: "alert.force_reload_done.info".localized
)
})
}
@objc public func openActiveConfigFolder() {
Actions.openPhpConfigFolder(version: App.shared.currentVersion!.short)
if (App.shared.currentVersion!.error) {
// php version was not identified
Actions.openGenericPhpConfigFolder()
} else {
// php version was identified
Actions.openPhpConfigFolder(version: App.shared.currentVersion!.short)
}
}
@objc public func openValetConfigFolder() {
@ -216,35 +240,9 @@ class MainMenu: NSObject, NSWindowDelegate {
}
}
@objc public func toggleXdebug() {
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
DispatchQueue.main.async {
self.setStatusBar(image: NSImage(named: NSImage.Name("StatusBarIcon"))!)
}
Actions.toggleXdebug()
DispatchQueue.main.async {
self.updatePhpVersionInStatusBar()
self.update()
}
}
}
@objc public func fixMyPhp() {
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
DispatchQueue.main.async {
Alert.present(messageText: "PHP Monitor will force reload the latest version of PHP", informativeText: "This can take a while. You'll get another alert when the force reload has completed.")
App.shared.busy = true
self.updatePhpVersionInStatusBar()
self.update()
}
Actions.fixMyPhp()
DispatchQueue.main.async {
Alert.present(messageText: "PHP has been force reloaded", informativeText: "All appropriate services have been restarted, and the latest version of PHP is now active. You can now try switching to another version of PHP.")
App.shared.busy = false
self.updatePhpVersionInStatusBar()
self.update()
}
}
@objc public func openAbout() {
NSApplication.shared.activate(ignoringOtherApps: true)
NSApplication.shared.orderFrontStandardAboutPanel()
}
func windowWillClose(_ notification: Notification) {