jel/Jel/Controllers/SettingsController.swift

45 lines
937 B
Swift

//
// SettingsController.swift
// Jel
//
// Created by zerocool on 12/13/23.
//
import Foundation
enum AppearanceState: Int, CaseIterable, Identifiable, CustomStringConvertible {
case automatic
case light
case dark
var id: Self { self }
var description: String {
switch self {
case .light:
return "Light"
case .dark:
return "Dark"
case .automatic:
return "Automatic"
}
}
}
class SettingsController: ObservableObject {
static let shared: SettingsController = SettingsController()
@Published var appearance: AppearanceState = .automatic
private let defaults = UserDefaults.standard
func save() {
defaults.set(self.appearance.rawValue, forKey: "Settings_appearance")
}
func load() {
let oldAppearance = defaults.integer(forKey: "Settings_appearance")
self.appearance = AppearanceState(rawValue: oldAppearance) ?? .automatic
}
}