mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
✨ Correctly load presets from config file
This commit is contained in:
@ -117,6 +117,7 @@
|
|||||||
C44CCD4127AFE2FC00CE40E5 /* AlertableError.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44CCD3F27AFE2FC00CE40E5 /* AlertableError.swift */; };
|
C44CCD4127AFE2FC00CE40E5 /* AlertableError.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44CCD3F27AFE2FC00CE40E5 /* AlertableError.swift */; };
|
||||||
C44CCD4927AFF3B700CE40E5 /* MainMenu+Async.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44CCD4827AFF3B700CE40E5 /* MainMenu+Async.swift */; };
|
C44CCD4927AFF3B700CE40E5 /* MainMenu+Async.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44CCD4827AFF3B700CE40E5 /* MainMenu+Async.swift */; };
|
||||||
C44CCD4A27AFF3BC00CE40E5 /* MainMenu+Async.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44CCD4827AFF3B700CE40E5 /* MainMenu+Async.swift */; };
|
C44CCD4A27AFF3BC00CE40E5 /* MainMenu+Async.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44CCD4827AFF3B700CE40E5 /* MainMenu+Async.swift */; };
|
||||||
|
C44F868E2835BD8D005C353A /* phpmon-config.json in Resources */ = {isa = PBXBuildFile; fileRef = C44F868D2835BD8D005C353A /* phpmon-config.json */; };
|
||||||
C459B4BD27F6093700E9B4B4 /* nginx-proxy.test in Resources */ = {isa = PBXBuildFile; fileRef = C459B4BC27F6093700E9B4B4 /* nginx-proxy.test */; };
|
C459B4BD27F6093700E9B4B4 /* nginx-proxy.test in Resources */ = {isa = PBXBuildFile; fileRef = C459B4BC27F6093700E9B4B4 /* nginx-proxy.test */; };
|
||||||
C464ADAC275A7A3F003FCD53 /* DomainListWC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADAB275A7A3F003FCD53 /* DomainListWC.swift */; };
|
C464ADAC275A7A3F003FCD53 /* DomainListWC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADAB275A7A3F003FCD53 /* DomainListWC.swift */; };
|
||||||
C464ADAD275A7A3F003FCD53 /* DomainListWC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADAB275A7A3F003FCD53 /* DomainListWC.swift */; };
|
C464ADAD275A7A3F003FCD53 /* DomainListWC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADAB275A7A3F003FCD53 /* DomainListWC.swift */; };
|
||||||
@ -265,6 +266,7 @@
|
|||||||
C4F780CE25D80B75000DBC97 /* LocalNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = C474B00524C0E98C00066A22 /* LocalNotification.swift */; };
|
C4F780CE25D80B75000DBC97 /* LocalNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = C474B00524C0E98C00066A22 /* LocalNotification.swift */; };
|
||||||
C4F8C0A422D4F12C002EFE61 /* DateExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8C0A322D4F12C002EFE61 /* DateExtension.swift */; };
|
C4F8C0A422D4F12C002EFE61 /* DateExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8C0A322D4F12C002EFE61 /* DateExtension.swift */; };
|
||||||
C4FBFC532616485F00CDB8E1 /* PhpVersionDetectionTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4FBFC512616485F00CDB8E1 /* PhpVersionDetectionTest.swift */; };
|
C4FBFC532616485F00CDB8E1 /* PhpVersionDetectionTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4FBFC512616485F00CDB8E1 /* PhpVersionDetectionTest.swift */; };
|
||||||
|
C4FC21B128391F8E00D368BB /* MainMenu+Actions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F361602836BFD9003598CC /* MainMenu+Actions.swift */; };
|
||||||
C4FE011128084FC200D1DE6D /* SelectionVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4FE011028084FC200D1DE6D /* SelectionVC.swift */; };
|
C4FE011128084FC200D1DE6D /* SelectionVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4FE011028084FC200D1DE6D /* SelectionVC.swift */; };
|
||||||
C4FE011228084FC200D1DE6D /* SelectionVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4FE011028084FC200D1DE6D /* SelectionVC.swift */; };
|
C4FE011228084FC200D1DE6D /* SelectionVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4FE011028084FC200D1DE6D /* SelectionVC.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
@ -350,6 +352,7 @@
|
|||||||
C44C1990276E44CB0072762D /* ProgressWindow.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = ProgressWindow.storyboard; sourceTree = "<group>"; };
|
C44C1990276E44CB0072762D /* ProgressWindow.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = ProgressWindow.storyboard; sourceTree = "<group>"; };
|
||||||
C44CCD3F27AFE2FC00CE40E5 /* AlertableError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertableError.swift; sourceTree = "<group>"; };
|
C44CCD3F27AFE2FC00CE40E5 /* AlertableError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertableError.swift; sourceTree = "<group>"; };
|
||||||
C44CCD4827AFF3B700CE40E5 /* MainMenu+Async.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MainMenu+Async.swift"; sourceTree = "<group>"; };
|
C44CCD4827AFF3B700CE40E5 /* MainMenu+Async.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MainMenu+Async.swift"; sourceTree = "<group>"; };
|
||||||
|
C44F868D2835BD8D005C353A /* phpmon-config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "phpmon-config.json"; sourceTree = "<group>"; };
|
||||||
C459B4BC27F6093700E9B4B4 /* nginx-proxy.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "nginx-proxy.test"; sourceTree = "<group>"; };
|
C459B4BC27F6093700E9B4B4 /* nginx-proxy.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "nginx-proxy.test"; sourceTree = "<group>"; };
|
||||||
C464ADAB275A7A3F003FCD53 /* DomainListWC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainListWC.swift; sourceTree = "<group>"; };
|
C464ADAB275A7A3F003FCD53 /* DomainListWC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainListWC.swift; sourceTree = "<group>"; };
|
||||||
C464ADAE275A7A69003FCD53 /* DomainListVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainListVC.swift; sourceTree = "<group>"; };
|
C464ADAE275A7A69003FCD53 /* DomainListVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainListVC.swift; sourceTree = "<group>"; };
|
||||||
@ -551,6 +554,7 @@
|
|||||||
C40C7F1C27720E1400DDDCDC /* Test Files */ = {
|
C40C7F1C27720E1400DDDCDC /* Test Files */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
C44F868C2835BD60005C353A /* phpmon */,
|
||||||
C459B4C127F6097E00E9B4B4 /* php */,
|
C459B4C127F6097E00E9B4B4 /* php */,
|
||||||
C459B4C027F6096300E9B4B4 /* valet */,
|
C459B4C027F6096300E9B4B4 /* valet */,
|
||||||
C459B4BF27F6094100E9B4B4 /* brew */,
|
C459B4BF27F6094100E9B4B4 /* brew */,
|
||||||
@ -680,6 +684,14 @@
|
|||||||
path = Errors;
|
path = Errors;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
C44F868C2835BD60005C353A /* phpmon */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
C44F868D2835BD8D005C353A /* phpmon-config.json */,
|
||||||
|
);
|
||||||
|
path = phpmon;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
C459B4BE27F6093A00E9B4B4 /* nginx */ = {
|
C459B4BE27F6093A00E9B4B4 /* nginx */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@ -1120,6 +1132,7 @@
|
|||||||
C42CFB1827DFDFDC00862737 /* nginx-site-isolated.test in Resources */,
|
C42CFB1827DFDFDC00862737 /* nginx-site-isolated.test in Resources */,
|
||||||
C4F780A825D80AE8000DBC97 /* php.ini in Resources */,
|
C4F780A825D80AE8000DBC97 /* php.ini in Resources */,
|
||||||
C4068CA527B0780A00544CD5 /* CheckboxPreferenceView.xib in Resources */,
|
C4068CA527B0780A00544CD5 /* CheckboxPreferenceView.xib in Resources */,
|
||||||
|
C44F868E2835BD8D005C353A /* phpmon-config.json in Resources */,
|
||||||
C43A8A2025D9D1D700591B77 /* brew-formula.json in Resources */,
|
C43A8A2025D9D1D700591B77 /* brew-formula.json in Resources */,
|
||||||
C4AF9F72275445FF00D44ED0 /* valet-config.json in Resources */,
|
C4AF9F72275445FF00D44ED0 /* valet-config.json in Resources */,
|
||||||
C44C1992276E44CB0072762D /* ProgressWindow.storyboard in Resources */,
|
C44C1992276E44CB0072762D /* ProgressWindow.storyboard in Resources */,
|
||||||
@ -1322,6 +1335,7 @@
|
|||||||
C4F2E4382752F08D0020E974 /* HomebrewDiagnostics.swift in Sources */,
|
C4F2E4382752F08D0020E974 /* HomebrewDiagnostics.swift in Sources */,
|
||||||
C4F780AE25D80B37000DBC97 /* PhpExtensionTest.swift in Sources */,
|
C4F780AE25D80B37000DBC97 /* PhpExtensionTest.swift in Sources */,
|
||||||
C4C8E819276F54D8003AC782 /* App+ConfigWatch.swift in Sources */,
|
C4C8E819276F54D8003AC782 /* App+ConfigWatch.swift in Sources */,
|
||||||
|
C4FC21B128391F8E00D368BB /* MainMenu+Actions.swift in Sources */,
|
||||||
54D9E0B927E4F51E003B9AD9 /* KeyCombo.swift in Sources */,
|
54D9E0B927E4F51E003B9AD9 /* KeyCombo.swift in Sources */,
|
||||||
C4EED88A27A48778006D7272 /* InterAppHandler.swift in Sources */,
|
C4EED88A27A48778006D7272 /* InterAppHandler.swift in Sources */,
|
||||||
C48D6C75279CD3E400F26D7E /* PhpVersionNumberTest.swift in Sources */,
|
C48D6C75279CD3E400F26D7E /* PhpVersionNumberTest.swift in Sources */,
|
||||||
@ -1548,7 +1562,7 @@
|
|||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 795;
|
CURRENT_PROJECT_VERSION = 800;
|
||||||
DEBUG = YES;
|
DEBUG = YES;
|
||||||
DEVELOPMENT_TEAM = 8M54J5J787;
|
DEVELOPMENT_TEAM = 8M54J5J787;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
@ -1574,7 +1588,7 @@
|
|||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 795;
|
CURRENT_PROJECT_VERSION = 800;
|
||||||
DEBUG = NO;
|
DEBUG = NO;
|
||||||
DEVELOPMENT_TEAM = 8M54J5J787;
|
DEVELOPMENT_TEAM = 8M54J5J787;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
|
34
phpmon-tests/Test Files/phpmon/phpmon-config.json
Normal file
34
phpmon-tests/Test Files/phpmon/phpmon-config.json
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"scan_apps": [],
|
||||||
|
"presets": [
|
||||||
|
{
|
||||||
|
"name": "Default PHP",
|
||||||
|
"extensions": {
|
||||||
|
"xdebug": false
|
||||||
|
},
|
||||||
|
"configuration": {
|
||||||
|
"memory_limit": "128M"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Personal Site",
|
||||||
|
"extensions": {
|
||||||
|
"xdebug": true
|
||||||
|
},
|
||||||
|
"configuration": {
|
||||||
|
"xdebug.mode": "coverage",
|
||||||
|
"memory_limit": "512M"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "PHP Monitor",
|
||||||
|
"extensions": {
|
||||||
|
"xdebug": true
|
||||||
|
},
|
||||||
|
"configuration": {
|
||||||
|
"xdebug.mode": "coverage",
|
||||||
|
"memory_limit": "512M"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -27,3 +27,25 @@ extension NSMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - NSMenuItem subclasses
|
||||||
|
|
||||||
|
class PhpMenuItem: NSMenuItem {
|
||||||
|
var version: String = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
class XdebugMenuItem: NSMenuItem {
|
||||||
|
var mode: String = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExtensionMenuItem: NSMenuItem {
|
||||||
|
var phpExtension: PhpExtension?
|
||||||
|
}
|
||||||
|
|
||||||
|
class EditorMenuItem: NSMenuItem {
|
||||||
|
var editor: Application?
|
||||||
|
}
|
||||||
|
|
||||||
|
class PresetMenuItem: NSMenuItem {
|
||||||
|
var preset: CustomPrefs.Preset?
|
||||||
|
}
|
||||||
|
@ -145,6 +145,12 @@ extension MainMenu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func togglePreset(sender: PresetMenuItem) {
|
||||||
|
asyncExecution {
|
||||||
|
dump(sender.preset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@objc func openPhpInfo() {
|
@objc func openPhpInfo() {
|
||||||
var url: URL?
|
var url: URL?
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ class StatusMenu: NSMenu {
|
|||||||
self.addItem(NSMenuItem.separator())
|
self.addItem(NSMenuItem.separator())
|
||||||
|
|
||||||
self.addXdebugMenuItem()
|
self.addXdebugMenuItem()
|
||||||
|
self.addPresetsMenuItem()
|
||||||
|
|
||||||
self.addFirstAidAndServicesMenuItems()
|
self.addFirstAidAndServicesMenuItems()
|
||||||
}
|
}
|
||||||
@ -140,6 +141,43 @@ class StatusMenu: NSMenu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addPresetsMenuItem() {
|
||||||
|
if Preferences.custom.presets.isEmpty {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let presets = NSMenuItem(title: "Configuration Presets", action: nil, keyEquivalent: "")
|
||||||
|
let presetsMenu = NSMenu()
|
||||||
|
presetsMenu.addItem(NSMenuItem.separator())
|
||||||
|
presetsMenu.addItem(HeaderView.asMenuItem(text: "Apply Configuration Presets"))
|
||||||
|
|
||||||
|
for preset in Preferences.custom.presets {
|
||||||
|
let presetMenuItem = PresetMenuItem(
|
||||||
|
title: "\(preset.name) (\(preset.extensions.count) extension, \(preset.configuration.count) prefs)",
|
||||||
|
action: #selector(MainMenu.togglePreset(sender:)),
|
||||||
|
keyEquivalent: ""
|
||||||
|
)
|
||||||
|
presetMenuItem.preset = preset
|
||||||
|
presetsMenu.addItem(presetMenuItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
presetsMenu.addItem(NSMenuItem.separator())
|
||||||
|
presetsMenu.addItem(NSMenuItem(
|
||||||
|
title: "Revert to Previous Configuration...",
|
||||||
|
action: #selector(MainMenu.restartDnsMasq), keyEquivalent: "")
|
||||||
|
)
|
||||||
|
presetsMenu.addItem(NSMenuItem.separator())
|
||||||
|
presetsMenu.addItem(NSMenuItem(
|
||||||
|
title: "\(Preferences.custom.presets.count) profiles loaded from configuration file",
|
||||||
|
action: nil, keyEquivalent: "")
|
||||||
|
)
|
||||||
|
for item in presetsMenu.items {
|
||||||
|
item.target = MainMenu.shared
|
||||||
|
}
|
||||||
|
self.setSubmenu(presetsMenu, for: presets)
|
||||||
|
self.addItem(presets)
|
||||||
|
}
|
||||||
|
|
||||||
func addXdebugMenuItem() {
|
func addXdebugMenuItem() {
|
||||||
if !Xdebug.enabled {
|
if !Xdebug.enabled {
|
||||||
return
|
return
|
||||||
@ -289,21 +327,3 @@ class StatusMenu: NSMenu {
|
|||||||
self.addItem(menuItem)
|
self.addItem(menuItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - NSMenuItem subclasses
|
|
||||||
|
|
||||||
class PhpMenuItem: NSMenuItem {
|
|
||||||
var version: String = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
class XdebugMenuItem: NSMenuItem {
|
|
||||||
var mode: String = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
class ExtensionMenuItem: NSMenuItem {
|
|
||||||
var phpExtension: PhpExtension?
|
|
||||||
}
|
|
||||||
|
|
||||||
class EditorMenuItem: NSMenuItem {
|
|
||||||
var editor: Application?
|
|
||||||
}
|
|
||||||
|
@ -10,8 +10,16 @@ import Foundation
|
|||||||
|
|
||||||
struct CustomPrefs: Decodable {
|
struct CustomPrefs: Decodable {
|
||||||
let scanApps: [String]
|
let scanApps: [String]
|
||||||
|
let presets: [Preset]
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case scanApps = "scan_apps"
|
case scanApps = "scan_apps"
|
||||||
|
case presets = "presets"
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Preset: Decodable {
|
||||||
|
let name: String
|
||||||
|
let extensions: [String: Bool]
|
||||||
|
let configuration: [String: String?]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ class Preferences {
|
|||||||
public init() {
|
public init() {
|
||||||
Preferences.handleFirstTimeLaunch()
|
Preferences.handleFirstTimeLaunch()
|
||||||
cachedPreferences = Self.cache()
|
cachedPreferences = Self.cache()
|
||||||
customPreferences = CustomPrefs(scanApps: [])
|
customPreferences = CustomPrefs(scanApps: [], presets: [])
|
||||||
loadCustomPreferences()
|
loadCustomPreferences()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +188,9 @@ class Preferences {
|
|||||||
CustomPrefs.self,
|
CustomPrefs.self,
|
||||||
from: try! String(contentsOf: url, encoding: .utf8).data(using: .utf8)!
|
from: try! String(contentsOf: url, encoding: .utf8).data(using: .utf8)!
|
||||||
)
|
)
|
||||||
|
|
||||||
Log.info("The .phpmon.conf.json file was successfully parsed.")
|
Log.info("The .phpmon.conf.json file was successfully parsed.")
|
||||||
|
Log.info("There are \(customPreferences.presets.count) custom presets.")
|
||||||
} catch {
|
} catch {
|
||||||
Log.warn("The .phpmon.conf.json file seems to be missing or malformed.")
|
Log.warn("The .phpmon.conf.json file seems to be missing or malformed.")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user