mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-04-07 03:20:09 +02:00
✨ Load custom preferences file
This commit is contained in:
17
phpmon/Domain/Preferences/CustomPrefs.swift
Normal file
17
phpmon/Domain/Preferences/CustomPrefs.swift
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// CustomPrefs.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 03/01/2022.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct CustomPrefs: Decodable {
|
||||
let scanApps: [String]
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case scanApps = "scan_apps"
|
||||
}
|
||||
}
|
||||
@@ -24,11 +24,21 @@ class Preferences {
|
||||
|
||||
static var shared = Preferences()
|
||||
|
||||
var customPreferences: CustomPrefs
|
||||
|
||||
var cachedPreferences: [PreferenceName: Any?]
|
||||
|
||||
public init() {
|
||||
Preferences.handleFirstTimeLaunch()
|
||||
cachedPreferences = Self.cache()
|
||||
do {
|
||||
customPreferences = try JSONDecoder().decode(
|
||||
CustomPrefs.self,
|
||||
from: try! String(contentsOf: URL(fileURLWithPath: "/Users/\(Paths.whoami)/.phpmon.conf.json"), encoding: .utf8).data(using: .utf8)!
|
||||
)
|
||||
} catch {
|
||||
customPreferences = CustomPrefs(scanApps: [])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - First Time Run
|
||||
|
||||
Reference in New Issue
Block a user