forked from masorange/ClaudeUsageTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreferencesManager.swift
More file actions
42 lines (36 loc) · 1.21 KB
/
PreferencesManager.swift
File metadata and controls
42 lines (36 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Foundation
import SwiftUI
enum AccountFilter: String, CaseIterable {
case all = "all"
case workOnly = "workOnly"
case personalOnly = "personalOnly"
}
class PreferencesManager: ObservableObject {
private let showCostKey = "showCostInStatusBar"
private let accountFilterKey = "accountFilter"
@Published var showCostInStatusBar: Bool {
didSet {
UserDefaults.standard.set(showCostInStatusBar, forKey: showCostKey)
}
}
@Published var accountFilter: AccountFilter {
didSet {
UserDefaults.standard.set(accountFilter.rawValue, forKey: accountFilterKey)
}
}
init() {
// Default to true (showing cost) if not set
if UserDefaults.standard.object(forKey: showCostKey) != nil {
self.showCostInStatusBar = UserDefaults.standard.bool(forKey: showCostKey)
} else {
self.showCostInStatusBar = true
}
// Default to .all if not set
if let filterRaw = UserDefaults.standard.string(forKey: accountFilterKey),
let filter = AccountFilter(rawValue: filterRaw) {
self.accountFilter = filter
} else {
self.accountFilter = .all
}
}
}