Procházet zdrojové kódy

Refactor snooze handling in SnoozeStateModel and UserNotificationsManager to eliminate unnecessary Task usage and improve date handling logic for snooze duration.

Trio Build Bot před 1 měsícem
rodič
revize
84d8d8e5c1

+ 2 - 4
Trio/Sources/Modules/Snooze/SnoozeStateModel.swift

@@ -38,9 +38,7 @@ extension Snooze {
 
 
 extension Snooze.StateModel: SnoozeObserver {
 extension Snooze.StateModel: SnoozeObserver {
     func snoozeDidChange(_ untilDate: Date) {
     func snoozeDidChange(_ untilDate: Date) {
-        Task { @MainActor in
-            snoozeUntilDate = untilDate
-            alarm = glucoseStorage.alarm
-        }
+        snoozeUntilDate = untilDate
+        alarm = glucoseStorage.alarm
     }
     }
 }
 }

+ 1 - 1
Trio/Sources/Services/UserNotifications/UserNotificationsManager.swift

@@ -471,7 +471,7 @@ final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, In
     }
     }
 
 
     @MainActor func applySnooze(for duration: TimeInterval) async {
     @MainActor func applySnooze(for duration: TimeInterval) async {
-        let untilDate = Date().addingTimeInterval(duration)
+        let untilDate = duration > 0 ? Date().addingTimeInterval(duration) : .distantPast
         snoozeUntilDate = untilDate
         snoozeUntilDate = untilDate
         lastGlucoseAlertToken = ""
         lastGlucoseAlertToken = ""
         // removeGlucoseNotifications() is safe to call here since we're @MainActor
         // removeGlucoseNotifications() is safe to call here since we're @MainActor