mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-12-21 03:10:06 +01:00
♻️ Update preferences
This commit is contained in:
@@ -9,6 +9,10 @@ import SwiftUI
|
|||||||
|
|
||||||
struct Localization {
|
struct Localization {
|
||||||
static var preferredLanguage: String? {
|
static var preferredLanguage: String? {
|
||||||
|
if Preferences.shared == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
guard let language = Preferences.preferences[.languageOverride] as? String else {
|
guard let language = Preferences.preferences[.languageOverride] as? String else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ public struct TestableConfiguration: Codable {
|
|||||||
Log.separator()
|
Log.separator()
|
||||||
Log.info("Applying to container...")
|
Log.info("Applying to container...")
|
||||||
App.shared.container.overrideWith(config: self)
|
App.shared.container.overrideWith(config: self)
|
||||||
|
Preferences.shared = Preferences(App.shared.container)
|
||||||
Log.info("Applying temporary preference overrides...")
|
Log.info("Applying temporary preference overrides...")
|
||||||
preferenceOverrides.forEach { (key: PreferenceName, value: Any?) in
|
preferenceOverrides.forEach { (key: PreferenceName, value: Any?) in
|
||||||
Preferences.shared.cachedPreferences[key] = value
|
Preferences.shared.cachedPreferences[key] = value
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ extension MainMenu {
|
|||||||
await BrewDiagnostics.shared.checkForOutdatedPhpInstallationSymlinks()
|
await BrewDiagnostics.shared.checkForOutdatedPhpInstallationSymlinks()
|
||||||
|
|
||||||
// Initialize preferences
|
// Initialize preferences
|
||||||
_ = Preferences.shared
|
Preferences.shared = Preferences(container)
|
||||||
|
|
||||||
// Put some useful diagnostics information in log
|
// Put some useful diagnostics information in log
|
||||||
BrewDiagnostics.shared.logBootInformation()
|
BrewDiagnostics.shared.logBootInformation()
|
||||||
|
|||||||
@@ -45,14 +45,14 @@ struct CustomPrefs: Decodable {
|
|||||||
extension Preferences {
|
extension Preferences {
|
||||||
func loadCustomPreferences() async {
|
func loadCustomPreferences() async {
|
||||||
// Ensure the configuration directory is created if missing
|
// 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
|
// Move the legacy file
|
||||||
await moveOutdatedConfigurationFile()
|
await moveOutdatedConfigurationFile()
|
||||||
|
|
||||||
// Attempt to load the file if it exists
|
// Attempt to load the file if it exists
|
||||||
let url = URL(fileURLWithPath: "\(App.shared.container.paths.homePath)/.config/phpmon/config.json")
|
let url = URL(fileURLWithPath: "\(container.paths.homePath)/.config/phpmon/config.json")
|
||||||
if App.shared.container.filesystem.fileExists(url.path) {
|
if container.filesystem.fileExists(url.path) {
|
||||||
|
|
||||||
Log.info("A custom ~/.config/phpmon/config.json file was found. Attempting to parse...")
|
Log.info("A custom ~/.config/phpmon/config.json file was found. Attempting to parse...")
|
||||||
loadCustomPreferencesFile(url)
|
loadCustomPreferencesFile(url)
|
||||||
@@ -62,9 +62,9 @@ extension Preferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func moveOutdatedConfigurationFile() async {
|
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...")
|
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!")
|
Log.info("The configuration file was copied successfully!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,16 +9,17 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
class Preferences {
|
class Preferences {
|
||||||
|
|
||||||
// MARK: - Singleton
|
// MARK: - Singleton
|
||||||
|
static var shared: Preferences!
|
||||||
|
|
||||||
static var shared = Preferences()
|
var container: Container
|
||||||
|
|
||||||
var customPreferences: CustomPrefs
|
var customPreferences: CustomPrefs
|
||||||
|
|
||||||
var cachedPreferences: [PreferenceName: Any?]
|
var cachedPreferences: [PreferenceName: Any?]
|
||||||
|
|
||||||
public init() {
|
public init(_ container: Container) {
|
||||||
|
self.container = container
|
||||||
Preferences.handleFirstTimeLaunch()
|
Preferences.handleFirstTimeLaunch()
|
||||||
cachedPreferences = Self.cache()
|
cachedPreferences = Self.cache()
|
||||||
customPreferences = CustomPrefs(
|
customPreferences = CustomPrefs(
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
},
|
},
|
||||||
"testTargets" : [
|
"testTargets" : [
|
||||||
{
|
{
|
||||||
|
"enabled" : false,
|
||||||
|
"parallelizable" : false,
|
||||||
"target" : {
|
"target" : {
|
||||||
"containerPath" : "container:PHP Monitor.xcodeproj",
|
"containerPath" : "container:PHP Monitor.xcodeproj",
|
||||||
"identifier" : "C471E7AC28F9B4940021E251",
|
"identifier" : "C471E7AC28F9B4940021E251",
|
||||||
@@ -27,6 +29,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"enabled" : false,
|
||||||
"parallelizable" : false,
|
"parallelizable" : false,
|
||||||
"target" : {
|
"target" : {
|
||||||
"containerPath" : "container:PHP Monitor.xcodeproj",
|
"containerPath" : "container:PHP Monitor.xcodeproj",
|
||||||
|
|||||||
Reference in New Issue
Block a user