Skip to content

Commit fa8b65b

Browse files
committed
refactor(AppState, ExitStateMachine, Settings): remove unused code and simplify delay logic for improved readability and maintainability
1 parent 30707f0 commit fa8b65b

3 files changed

Lines changed: 6 additions & 13 deletions

File tree

SaveEye/Models/AppState.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ class AppState: ObservableObject {
4646
// 恢复运行状态
4747
restoreRunningState()
4848

49-
// 确保护眼窗口在后台创建
50-
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
51-
self.ensureEyeCareWindowExists()
52-
}
49+
5350
}
5451

5552
// 恢复运行状态
@@ -297,7 +294,6 @@ class AppState: ObservableObject {
297294
}
298295

299296
private func closeAllEyeCareWindows() {
300-
_ = eyeCareWindows.count
301297
for window in eyeCareWindows {
302298
window.close()
303299
}
@@ -312,5 +308,5 @@ class AppState: ObservableObject {
312308
}
313309
}
314310

315-
func ensureEyeCareWindowExists() {}
311+
316312
}

SaveEye/Models/ExitStateMachine.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class ExitStateMachine: ObservableObject {
1919
private weak var settings: Settings?
2020

2121
private let clickWindow: TimeInterval = 2.0
22+
23+
private var delayMinutes: Int {
24+
return settings?.delayDurationMinutes ?? 5
25+
}
2226

2327
enum ExitState {
2428
case idle
@@ -69,7 +73,6 @@ class ExitStateMachine: ObservableObject {
6973
private func enterThirdPress() {
7074
currentState = .thirdPress
7175
pressCount = 3
72-
let delayMinutes = settings?.delayDurationMinutes ?? 5
7376
showMessage = "延迟\(delayMinutes)分钟后继续工作..."
7477

7578
timer?.invalidate()
@@ -81,7 +84,6 @@ class ExitStateMachine: ObservableObject {
8184
}
8285

8386
private func handleDelayEscape() {
84-
let delayMinutes = settings?.delayDurationMinutes ?? 5
8587
showMessage = "延迟\(delayMinutes)分钟,继续工作..."
8688

8789
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
@@ -111,7 +113,6 @@ class ExitStateMachine: ObservableObject {
111113
func enterDelayState() {
112114
currentState = .delayRequest
113115
pressCount = 0
114-
let delayMinutes = settings?.delayDurationMinutes ?? 5
115116
showMessage = "是否需要延迟休息?按ESC延迟\(delayMinutes)分钟"
116117

117118
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) {

SaveEye/Models/Settings.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ class Settings: ObservableObject {
6464

6565
isProtectionRunning = UserDefaults.standard.bool(forKey: "isProtectionRunning")
6666
lastWorkStartTime = UserDefaults.standard.object(forKey: "lastWorkStartTime") as? Date
67-
68-
if breakIntervalMinutes < 1 { breakIntervalMinutes = 1 }
69-
if restDurationSeconds < 5 { restDurationSeconds = 5 }
70-
if delayDurationMinutes < 1 { delayDurationMinutes = 1 }
7167
}
7268

7369
private func updateAutoStart() {

0 commit comments

Comments
 (0)