getting going

This commit is contained in:
Michael Freno
2026-01-08 00:31:34 -05:00
parent c2c5736bfd
commit 658bbd8e02
24 changed files with 2058 additions and 1 deletions

View File

@@ -0,0 +1,73 @@
//
// SettingsManager.swift
// Gaze
//
// Created by Mike Freno on 1/7/26.
//
import Foundation
import Combine
@MainActor
class SettingsManager: ObservableObject {
static let shared = SettingsManager()
@Published var settings: AppSettings {
didSet {
save()
}
}
private let userDefaults = UserDefaults.standard
private let settingsKey = "gazeAppSettings"
private init() {
self.settings = Self.loadSettings()
}
private static func loadSettings() -> AppSettings {
guard let data = UserDefaults.standard.data(forKey: "gazeAppSettings"),
let settings = try? JSONDecoder().decode(AppSettings.self, from: data) else {
return .defaults
}
return settings
}
func save() {
guard let data = try? JSONEncoder().encode(settings) else {
print("Failed to encode settings")
return
}
userDefaults.set(data, forKey: settingsKey)
}
func load() {
settings = Self.loadSettings()
}
func resetToDefaults() {
settings = .defaults
}
func timerConfiguration(for type: TimerType) -> TimerConfiguration {
switch type {
case .lookAway:
return settings.lookAwayTimer
case .blink:
return settings.blinkTimer
case .posture:
return settings.postureTimer
}
}
func updateTimerConfiguration(for type: TimerType, configuration: TimerConfiguration) {
switch type {
case .lookAway:
settings.lookAwayTimer = configuration
case .blink:
settings.blinkTimer = configuration
case .posture:
settings.postureTimer = configuration
}
}
}