mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
♻️ Rework loading of custom preferences
This commit is contained in:
@ -32,26 +32,7 @@ class Preferences {
|
||||
Preferences.handleFirstTimeLaunch()
|
||||
cachedPreferences = Self.cache()
|
||||
customPreferences = CustomPrefs(scanApps: [])
|
||||
|
||||
let url = URL(fileURLWithPath: "/Users/\(Paths.whoami)/.phpmon.conf.json")
|
||||
if Filesystem.fileExists(url.path) {
|
||||
Log.info("A custom .phpmon.conf.json file was found. Attempting to parse...")
|
||||
loadCustomPreferencesFile(url)
|
||||
} else {
|
||||
Log.info("There was no .phpmon.conf.json file to be loaded.")
|
||||
}
|
||||
}
|
||||
|
||||
private func loadCustomPreferencesFile(_ url: URL) {
|
||||
do {
|
||||
customPreferences = try JSONDecoder().decode(
|
||||
CustomPrefs.self,
|
||||
from: try! String(contentsOf: url, encoding: .utf8).data(using: .utf8)!
|
||||
)
|
||||
Log.info("The .phpmon.conf.json file was successfully parsed.")
|
||||
} catch {
|
||||
Log.warn("The .phpmon.conf.json file seems to be missing or malformed.")
|
||||
}
|
||||
loadCustomPreferences()
|
||||
}
|
||||
|
||||
// MARK: - First Time Run
|
||||
@ -133,4 +114,28 @@ class Preferences {
|
||||
Preferences.shared.cachedPreferences = Preferences.cache()
|
||||
}
|
||||
|
||||
// MARK: - Custom Preferences
|
||||
|
||||
private func loadCustomPreferences() {
|
||||
let url = URL(fileURLWithPath: "/Users/\(Paths.whoami)/.phpmon.conf.json")
|
||||
if Filesystem.fileExists(url.path) {
|
||||
Log.info("A custom .phpmon.conf.json file was found. Attempting to parse...")
|
||||
loadCustomPreferencesFile(url)
|
||||
} else {
|
||||
Log.info("There was no .phpmon.conf.json file to be loaded.")
|
||||
}
|
||||
}
|
||||
|
||||
private func loadCustomPreferencesFile(_ url: URL) {
|
||||
do {
|
||||
customPreferences = try JSONDecoder().decode(
|
||||
CustomPrefs.self,
|
||||
from: try! String(contentsOf: url, encoding: .utf8).data(using: .utf8)!
|
||||
)
|
||||
Log.info("The .phpmon.conf.json file was successfully parsed.")
|
||||
} catch {
|
||||
Log.warn("The .phpmon.conf.json file seems to be missing or malformed.")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user