-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsManager.swift
More file actions
96 lines (78 loc) · 2.1 KB
/
Copy pathSettingsManager.swift
File metadata and controls
96 lines (78 loc) · 2.1 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// SettingsManager.swift
// CaffeineMate
//
// Created by Edd on 07/10/2025.
//
import Foundation
class SettingsManager {
static let shared = SettingsManager()
private let defaults = UserDefaults.standard
// UserDefaults Keys
private enum Keys {
static let keepDisplayAwake = "keepDisplayAwake"
static let awakeDuration = "awakeDuration"
static let launchAtLogin = "launchAtLogin"
static let shortcutKey = "shortcutKey"
static let shortcutModifiers = "shortcutModifiers"
}
private init() {}
// MARK: - Keep Display Awake
var keepDisplayAwake: Bool {
get {
defaults.bool(forKey: Keys.keepDisplayAwake)
}
set {
defaults.set(newValue, forKey: Keys.keepDisplayAwake)
}
}
// MARK: - Duration (in minutes, 0 = indefinite)
var awakeDuration: Int {
get {
defaults.integer(forKey: Keys.awakeDuration)
}
set {
defaults.set(newValue, forKey: Keys.awakeDuration)
}
}
// MARK: - Launch at Login
var launchAtLogin: Bool {
get {
defaults.bool(forKey: Keys.launchAtLogin)
}
set {
defaults.set(newValue, forKey: Keys.launchAtLogin)
}
}
// MARK: - Keyboard Shortcut
var shortcutKey: String? {
get {
defaults.string(forKey: Keys.shortcutKey)
}
set {
defaults.set(newValue, forKey: Keys.shortcutKey)
}
}
var shortcutModifiers: UInt {
get {
UInt(defaults.integer(forKey: Keys.shortcutModifiers))
}
set {
defaults.set(Int(newValue), forKey: Keys.shortcutModifiers)
}
}
// MARK: - Convenience Methods
func getDurationMinutes() -> Int {
return awakeDuration
}
func setDurationMinutes(_ minutes: Int) {
awakeDuration = minutes
}
func resetToDefaults() {
keepDisplayAwake = false
awakeDuration = 0
launchAtLogin = false
shortcutKey = nil
shortcutModifiers = 0
}
}