1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-12-21 03:10:06 +01:00

♻️ Update preferences

This commit is contained in:
2025-10-16 14:13:47 +02:00
parent 91d7a4bf44
commit 546f01d55d
6 changed files with 18 additions and 9 deletions

View File

@@ -9,6 +9,10 @@ import SwiftUI
struct Localization {
static var preferredLanguage: String? {
if Preferences.shared == nil {
return nil
}
guard let language = Preferences.preferences[.languageOverride] as? String else {
return nil
}

View File

@@ -123,6 +123,7 @@ public struct TestableConfiguration: Codable {
Log.separator()
Log.info("Applying to container...")
App.shared.container.overrideWith(config: self)
Preferences.shared = Preferences(App.shared.container)
Log.info("Applying temporary preference overrides...")
preferenceOverrides.forEach { (key: PreferenceName, value: Any?) in
Preferences.shared.cachedPreferences[key] = value

View File

@@ -37,7 +37,7 @@ extension MainMenu {
await BrewDiagnostics.shared.checkForOutdatedPhpInstallationSymlinks()
// Initialize preferences
_ = Preferences.shared
Preferences.shared = Preferences(container)
// Put some useful diagnostics information in log
BrewDiagnostics.shared.logBootInformation()

View File

@@ -45,14 +45,14 @@ struct CustomPrefs: Decodable {
extension Preferences {
func loadCustomPreferences() async {
// Ensure the configuration directory is created if missing
await App.shared.container.shell.quiet("mkdir -p ~/.config/phpmon")
await container.shell.quiet("mkdir -p ~/.config/phpmon")
// Move the legacy file
await moveOutdatedConfigurationFile()
// Attempt to load the file if it exists
let url = URL(fileURLWithPath: "\(App.shared.container.paths.homePath)/.config/phpmon/config.json")
if App.shared.container.filesystem.fileExists(url.path) {
let url = URL(fileURLWithPath: "\(container.paths.homePath)/.config/phpmon/config.json")
if container.filesystem.fileExists(url.path) {
Log.info("A custom ~/.config/phpmon/config.json file was found. Attempting to parse...")
loadCustomPreferencesFile(url)
@@ -62,9 +62,9 @@ extension Preferences {
}
func moveOutdatedConfigurationFile() async {
if App.shared.container.filesystem.fileExists("~/.phpmon.conf.json") && !App.shared.container.filesystem.fileExists("~/.config/phpmon/config.json") {
if container.filesystem.fileExists("~/.phpmon.conf.json") && !container.filesystem.fileExists("~/.config/phpmon/config.json") {
Log.info("An outdated configuration file was found. Moving it...")
await App.shared.container.shell.quiet("cp ~/.phpmon.conf.json ~/.config/phpmon/config.json")
await container.shell.quiet("cp ~/.phpmon.conf.json ~/.config/phpmon/config.json")
Log.info("The configuration file was copied successfully!")
}
}

View File

@@ -9,16 +9,17 @@
import Foundation
class Preferences {
// MARK: - Singleton
static var shared: Preferences!
static var shared = Preferences()
var container: Container
var customPreferences: CustomPrefs
var cachedPreferences: [PreferenceName: Any?]
public init() {
public init(_ container: Container) {
self.container = container
Preferences.handleFirstTimeLaunch()
cachedPreferences = Self.cache()
customPreferences = CustomPrefs(

View File

@@ -13,6 +13,8 @@
},
"testTargets" : [
{
"enabled" : false,
"parallelizable" : false,
"target" : {
"containerPath" : "container:PHP Monitor.xcodeproj",
"identifier" : "C471E7AC28F9B4940021E251",
@@ -27,6 +29,7 @@
}
},
{
"enabled" : false,
"parallelizable" : false,
"target" : {
"containerPath" : "container:PHP Monitor.xcodeproj",