mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
✨ Add preferences dialog to enable static icon (#25)
This commit is contained in:
48
phpmon/Domain/Preferences/Preferences.swift
Normal file
48
phpmon/Domain/Preferences/Preferences.swift
Normal file
@ -0,0 +1,48 @@
|
||||
//
|
||||
// Preferences.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 30/03/2021.
|
||||
// Copyright © 2021 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum PreferenceName: String {
|
||||
case shouldDisplayDynamicIcon = "use_dynamic_icon"
|
||||
}
|
||||
|
||||
class Preferences {
|
||||
|
||||
static func handleFirstTimeLaunch() {
|
||||
let launchedBefore = UserDefaults.standard.bool(forKey: "alreadyLaunched")
|
||||
|
||||
if launchedBefore {
|
||||
return
|
||||
}
|
||||
|
||||
UserDefaults.standard.setValue(true, forKey: PreferenceName.shouldDisplayDynamicIcon.rawValue)
|
||||
UserDefaults.standard.setValue(true, forKey: "alreadyLaunched")
|
||||
UserDefaults.standard.synchronize()
|
||||
}
|
||||
|
||||
static func retrieve() -> [PreferenceName: Bool] {
|
||||
Preferences.handleFirstTimeLaunch()
|
||||
|
||||
return [
|
||||
.shouldDisplayDynamicIcon: UserDefaults.standard.bool(
|
||||
forKey: PreferenceName.shouldDisplayDynamicIcon.rawValue
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
static var preferences: [PreferenceName: Bool] {
|
||||
return Preferences.retrieve()
|
||||
}
|
||||
|
||||
static func update(_ preference: PreferenceName, value: Bool) {
|
||||
UserDefaults.standard.setValue(value, forKey: preference.rawValue)
|
||||
UserDefaults.standard.synchronize()
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user