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

Allow application of presets

This commit is contained in:
2022-05-29 12:32:48 +02:00
parent 382cb177be
commit 64491c6fe1
2 changed files with 35 additions and 1 deletions

View File

@ -147,7 +147,7 @@ extension MainMenu {
@objc func togglePreset(sender: PresetMenuItem) {
asyncExecution {
dump(sender.preset)
sender.preset?.apply()
}
}

View File

@ -21,5 +21,39 @@ struct CustomPrefs: Decodable {
let name: String
let extensions: [String: Bool]
let configuration: [String: String?]
public func apply() {
// Apply the configuration changes first
for conf in configuration {
applyConfigurationValue(key: conf.key, value: conf.value ?? "")
}
// Apply the extension changes in-place afterward
for ext in extensions {
for foundExt in PhpEnv.phpInstall.extensions
where foundExt.name == ext.key && foundExt.enabled != ext.value {
Log.info("Toggling extension \(foundExt.name) in \(foundExt.file)")
foundExt.toggle()
break
}
}
Actions.restartPhpFpm()
}
private func applyConfigurationValue(key: String, value: String) {
guard let file = PhpEnv.shared.getConfigFile(forKey: key) else {
return
}
do {
if file.has(key: key) {
Log.info("Setting config value \(key) in \(file.filePath)")
try file.replace(key: key, value: value)
}
} catch {
Log.err("Setting \(key) to \(value) failed.")
}
}
}
}