From 7e78026d0685145c1fa8a3277de20bf52be8a1e7 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 12 Sep 2023 19:26:10 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20WIP:=20PHP=20Config=20E?= =?UTF-8?q?ditor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Has UI height rendering issues (w/ SwiftUI) - Needs debounce on UI elements - Cannot currently persist modified settings - Cannot display On/Off settings - Cannot display regular text settings --- PHP Monitor.xcodeproj/project.pbxproj | 28 +++++++----- phpmon/Common/PHP/PhpConfigurationFile.swift | 3 +- phpmon/Domain/App/App.swift | 5 ++- phpmon/Domain/Menu/MainMenu.swift | 4 ++ phpmon/Domain/Menu/StatusMenu+Items.swift | 3 ++ .../Data/BytePhpPreference.swift | 7 +++ .../Data/PhpPreference.swift | 8 ++++ .../PHP Config Editor/UI/ByteLimitView.swift | 3 +- .../UI/ConfigManagerView.swift | 4 +- .../UI/ConfigManagerWindowController.swift | 45 +++++++++++++++++++ phpmon/en.lproj/Localizable.strings | 1 + 11 files changed, 94 insertions(+), 17 deletions(-) create mode 100644 phpmon/Modules/PHP Config Editor/UI/ConfigManagerWindowController.swift diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 377d70d..49c32df 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -132,6 +132,7 @@ C42CFB1627DFDE7900862737 /* nginx-site.test in Resources */ = {isa = PBXBuildFile; fileRef = C42CFB1527DFDE7900862737 /* nginx-site.test */; }; C42CFB1827DFDFDC00862737 /* nginx-site-isolated.test in Resources */ = {isa = PBXBuildFile; fileRef = C42CFB1727DFDFDC00862737 /* nginx-site-isolated.test */; }; C42CFB1A27DFE8BD00862737 /* NginxConfigurationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42CFB1927DFE8BD00862737 /* NginxConfigurationTest.swift */; }; + C42E3F772AB0D2880096DFC2 /* ConfigManagerWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42E3F762AB0D2880096DFC2 /* ConfigManagerWindowController.swift */; }; C42F26732805B4B400938AC7 /* ValetListable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42F26722805B4B400938AC7 /* ValetListable.swift */; }; C42F26742805B4B400938AC7 /* ValetListable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42F26722805B4B400938AC7 /* ValetListable.swift */; }; C42F26762805FEE200938AC7 /* nginx-secure-proxy.test in Resources */ = {isa = PBXBuildFile; fileRef = C42F26752805FEE200938AC7 /* nginx-secure-proxy.test */; }; @@ -929,6 +930,7 @@ C42CFB1527DFDE7900862737 /* nginx-site.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "nginx-site.test"; sourceTree = ""; }; C42CFB1727DFDFDC00862737 /* nginx-site-isolated.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "nginx-site-isolated.test"; sourceTree = ""; }; C42CFB1927DFE8BD00862737 /* NginxConfigurationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NginxConfigurationTest.swift; sourceTree = ""; }; + C42E3F762AB0D2880096DFC2 /* ConfigManagerWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigManagerWindowController.swift; sourceTree = ""; }; C42F26722805B4B400938AC7 /* ValetListable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValetListable.swift; sourceTree = ""; }; C42F26752805FEE200938AC7 /* nginx-secure-proxy.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "nginx-secure-proxy.test"; sourceTree = ""; }; C436039F275E67610028EFC6 /* AppDelegate+Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+Notifications.swift"; sourceTree = ""; }; @@ -1499,6 +1501,7 @@ children = ( C44DFA7B2A67043000B98ED5 /* ConfigManagerView.swift */, C4D5857B2A7038DB00DDBB63 /* ByteLimitView.swift */, + C42E3F762AB0D2880096DFC2 /* ConfigManagerWindowController.swift */, ); path = UI; sourceTree = ""; @@ -2568,6 +2571,7 @@ C4B97B75275CF08C003F3378 /* AppDelegate+MenuOutlets.swift in Sources */, C464ADAC275A7A3F003FCD53 /* DomainListWindowController.swift in Sources */, C4CB6E65292C362C002E9027 /* Homebrew.swift in Sources */, + C42E3F772AB0D2880096DFC2 /* ConfigManagerWindowController.swift in Sources */, C464ADB2275A87CA003FCD53 /* DomainListCellProtocol.swift in Sources */, C4EE188422D3386B00E126E5 /* Constants.swift in Sources */, C493084A279F331F009C240B /* AddSiteVC.swift in Sources */, @@ -3488,7 +3492,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1306; + CURRENT_PROJECT_VERSION = 1320; DEAD_CODE_STRIPPING = YES; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; @@ -3501,7 +3505,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.4; - MARKETING_VERSION = 6.1; + MARKETING_VERSION = 6.2; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -3519,7 +3523,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1306; + CURRENT_PROJECT_VERSION = 1320; DEAD_CODE_STRIPPING = YES; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; @@ -3532,7 +3536,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.4; - MARKETING_VERSION = 6.1; + MARKETING_VERSION = 6.2; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -3759,7 +3763,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1306; + CURRENT_PROJECT_VERSION = 1320; DEAD_CODE_STRIPPING = YES; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; @@ -3772,7 +3776,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.4; - MARKETING_VERSION = 6.1; + MARKETING_VERSION = 6.2; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.dev; PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_NAME = "$(TARGET_NAME) DEV"; @@ -3875,7 +3879,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1306; + CURRENT_PROJECT_VERSION = 1320; DEAD_CODE_STRIPPING = YES; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; @@ -3888,7 +3892,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.4; - MARKETING_VERSION = 6.1; + MARKETING_VERSION = 6.2; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.dev; PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_NAME = "$(TARGET_NAME) DEV"; @@ -3991,7 +3995,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1306; + CURRENT_PROJECT_VERSION = 1320; DEAD_CODE_STRIPPING = YES; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; @@ -4004,7 +4008,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.4; - MARKETING_VERSION = 6.1; + MARKETING_VERSION = 6.2; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.eap; PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_NAME = "$(TARGET_NAME) EAP"; @@ -4172,7 +4176,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1306; + CURRENT_PROJECT_VERSION = 1320; DEAD_CODE_STRIPPING = YES; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; @@ -4185,7 +4189,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.4; - MARKETING_VERSION = 6.1; + MARKETING_VERSION = 6.2; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.eap; PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_NAME = "$(TARGET_NAME) EAP"; diff --git a/phpmon/Common/PHP/PhpConfigurationFile.swift b/phpmon/Common/PHP/PhpConfigurationFile.swift index 9ce7907..42d5165 100644 --- a/phpmon/Common/PHP/PhpConfigurationFile.swift +++ b/phpmon/Common/PHP/PhpConfigurationFile.swift @@ -69,8 +69,9 @@ class PhpConfigurationFile: CreatedFromFile { return nil } - enum ReplacementErrors: Error { + public enum ReplacementErrors: Error { case missingKey + case missingFile } /** diff --git a/phpmon/Domain/App/App.swift b/phpmon/Domain/App/App.swift index f991591..3c89866 100644 --- a/phpmon/Domain/App/App.swift +++ b/phpmon/Domain/App/App.swift @@ -74,10 +74,13 @@ class App { /** The window controller of the onboarding window. */ var onboardingWindowController: OnboardingWindowController? + /** The window controller of the config manager window. */ + var phpConfigManagerWindowController: PhpConfigManagerWindowController? + /** The window controller of the warnings window. */ var phpDoctorWindowController: PhpDoctorWindowController? - /** The window controller of the warnings window. */ + /** The window controller of the PHP version manager window. */ var phpVersionManagerWindowController: PhpVersionManagerWindowController? /** List of detected (installed) applications that PHP Monitor can work with. */ diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index dcc0c09..c0288fc 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -206,6 +206,10 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate PhpDoctorWindowController.show() } + @objc func openConfigGUI() { + PhpConfigManagerWindowController.show() + } + @objc func openDomainList() { DomainListVC.show() } diff --git a/phpmon/Domain/Menu/StatusMenu+Items.swift b/phpmon/Domain/Menu/StatusMenu+Items.swift index fd9ca10..6b6642e 100644 --- a/phpmon/Domain/Menu/StatusMenu+Items.swift +++ b/phpmon/Domain/Menu/StatusMenu+Items.swift @@ -152,6 +152,9 @@ extension StatusMenu { NSMenuItem(title: "mi_php_version_manager".localized, action: #selector(MainMenu.openPhpVersionManager), keyEquivalent: "m"), + NSMenuItem(title: "mi_php_config_manager".localized, + action: #selector(MainMenu.openConfigGUI), + keyEquivalent: "g"), NSMenuItem(title: "mi_php_config".localized, action: #selector(MainMenu.openActiveConfigFolder), keyEquivalent: "c"), diff --git a/phpmon/Modules/PHP Config Editor/Data/BytePhpPreference.swift b/phpmon/Modules/PHP Config Editor/Data/BytePhpPreference.swift index 5a4adc3..6509737 100644 --- a/phpmon/Modules/PHP Config Editor/Data/BytePhpPreference.swift +++ b/phpmon/Modules/PHP Config Editor/Data/BytePhpPreference.swift @@ -53,6 +53,13 @@ class BytePhpPreference: PhpPreference { private func updatedFieldValue() { internalValue = "\(value)\(unit.rawValue)" + + do { + try PhpPreference.persistToIniFile(key: self.key, value: self.internalValue) + Log.info("The preference \(key) was updated to: \(value)") + } catch { + Log.info("The preference \(key) could not be updated") + } } public static func readFrom(internalValue: String) -> (UnitOption, Int)? { diff --git a/phpmon/Modules/PHP Config Editor/Data/PhpPreference.swift b/phpmon/Modules/PHP Config Editor/Data/PhpPreference.swift index b49dea0..a6d8fd3 100644 --- a/phpmon/Modules/PHP Config Editor/Data/PhpPreference.swift +++ b/phpmon/Modules/PHP Config Editor/Data/PhpPreference.swift @@ -15,6 +15,14 @@ class PhpPreference { init(key: String) { self.key = key } + + internal static func persistToIniFile(key: String, value: String) throws { + if let file = PhpEnvironments.shared.getConfigFile(forKey: key) { + try file.replace(key: key, value: value) + } + + throw PhpConfigurationFile.ReplacementErrors.missingFile + } } class BoolPhpPreference: PhpPreference { diff --git a/phpmon/Modules/PHP Config Editor/UI/ByteLimitView.swift b/phpmon/Modules/PHP Config Editor/UI/ByteLimitView.swift index 71cabab..c98c0d1 100644 --- a/phpmon/Modules/PHP Config Editor/UI/ByteLimitView.swift +++ b/phpmon/Modules/PHP Config Editor/UI/ByteLimitView.swift @@ -40,7 +40,7 @@ struct PreferenceContainer: View { .font(.subheadline) .fixedSize(horizontal: false, vertical: true) } - .frame(maxWidth: .infinity, alignment: .topLeading) + .frame(maxWidth: .infinity, maxHeight: 150, alignment: .topLeading) } } .padding(5) @@ -79,7 +79,6 @@ struct ByteLimitView: View { .pickerStyle(.menu) .onChange(of: unit) { newValue in self.preference.unit = newValue - print(self.preference.internalValue) } } } diff --git a/phpmon/Modules/PHP Config Editor/UI/ConfigManagerView.swift b/phpmon/Modules/PHP Config Editor/UI/ConfigManagerView.swift index dd9de19..28d72f3 100644 --- a/phpmon/Modules/PHP Config Editor/UI/ConfigManagerView.swift +++ b/phpmon/Modules/PHP Config Editor/UI/ConfigManagerView.swift @@ -13,7 +13,7 @@ struct ConfigManagerView: View { var preferences: [PhpPreference] = [ BytePhpPreference(key: "memory_limit"), BytePhpPreference(key: "post_max_size"), - BoolPhpPreference(key: "file_uploads"), + // BoolPhpPreference(key: "file_uploads"), BytePhpPreference(key: "upload_max_filesize") ] @@ -51,6 +51,7 @@ struct ConfigManagerView: View { if let preference = preference as? BytePhpPreference { ByteLimitView(preference: preference) } + /* if let preference = preference as? BoolPhpPreference { Toggle("", isOn: preference.$value) .toggleStyle(.switch) @@ -59,6 +60,7 @@ struct ConfigManagerView: View { if let preference = preference as? StringPhpPreference { TextField("Placeholder", text: preference.$value) } + */ }.frame(maxWidth: .infinity) } }.padding(10) diff --git a/phpmon/Modules/PHP Config Editor/UI/ConfigManagerWindowController.swift b/phpmon/Modules/PHP Config Editor/UI/ConfigManagerWindowController.swift new file mode 100644 index 0000000..ce0ab8f --- /dev/null +++ b/phpmon/Modules/PHP Config Editor/UI/ConfigManagerWindowController.swift @@ -0,0 +1,45 @@ +// +// ConfigManagerWindowController.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 12/09/2023. +// Copyright © 2023 Nico Verbruggen. All rights reserved. +// + +import Cocoa +import SwiftUI + +class PhpConfigManagerWindowController: PMWindowController { + + // MARK: - Window Identifier + + override var windowName: String { + return "ConfigManager" + } + + public static func create(delegate: NSWindowDelegate?) { + let windowController = Self() + windowController.window = NSWindow() + + guard let window = windowController.window else { return } + window.title = "" + window.styleMask = [.titled, .closable, .miniaturizable] + window.titlebarAppearsTransparent = true + window.delegate = delegate ?? windowController + window.contentView = NSHostingView(rootView: ConfigManagerView()) + window.setContentSize(NSSize(width: 600, height: 480)) + + App.shared.phpConfigManagerWindowController = windowController + } + + public static func show(delegate: NSWindowDelegate? = nil) { + if App.shared.phpConfigManagerWindowController == nil { + Self.create(delegate: delegate) + } + + App.shared.phpConfigManagerWindowController?.showWindow(self) + App.shared.phpConfigManagerWindowController?.window?.setCenterPosition(offsetY: 70) + + NSApp.activate(ignoringOtherApps: true) + } +} diff --git a/phpmon/en.lproj/Localizable.strings b/phpmon/en.lproj/Localizable.strings index 4c885ce..efc6d4f 100644 --- a/phpmon/en.lproj/Localizable.strings +++ b/phpmon/en.lproj/Localizable.strings @@ -13,6 +13,7 @@ "mi_fix_php_link" = "Fix Automatically..."; "mi_no_php_linked_explain" = "What's This?"; "mi_php_version_manager" = "PHP Version Manager..."; +"mi_php_config_manager" = "PHP Configuration Editor..."; "mi_diagnostics" = "Diagnostics"; "mi_active_services" = "Active Services";