diff options
author | Shav Kinderlehrer <[email protected]> | 2023-12-15 10:41:00 -0500 |
---|---|---|
committer | Shav Kinderlehrer <[email protected]> | 2023-12-15 10:41:00 -0500 |
commit | 2e3c12fed339c8bf3dc966217cbdf4c385fb98a1 (patch) | |
tree | 356a0bbfd24f98bf04545eb876cf20cd6179850e /Jel/Controllers/SettingsController.swift | |
parent | 3994a6f408905049a5c280a303e30fe636b07968 (diff) | |
download | jel-2e3c12fed339c8bf3dc966217cbdf4c385fb98a1.tar.gz jel-2e3c12fed339c8bf3dc966217cbdf4c385fb98a1.zip |
Add settings view + fix signin flow
Diffstat (limited to 'Jel/Controllers/SettingsController.swift')
-rw-r--r-- | Jel/Controllers/SettingsController.swift | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Jel/Controllers/SettingsController.swift b/Jel/Controllers/SettingsController.swift new file mode 100644 index 0000000..2b912c4 --- /dev/null +++ b/Jel/Controllers/SettingsController.swift @@ -0,0 +1,44 @@ +// +// 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 + } +} |