Selaa lähdekoodia

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

Trio Build Bot 1 kuukausi sitten
vanhempi
commit
84d8d8e5c1

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

@@ -38,9 +38,7 @@ extension Snooze {
 
 extension Snooze.StateModel: SnoozeObserver {
     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 {
-        let untilDate = Date().addingTimeInterval(duration)
+        let untilDate = duration > 0 ? Date().addingTimeInterval(duration) : .distantPast
         snoozeUntilDate = untilDate
         lastGlucoseAlertToken = ""
         // removeGlucoseNotifications() is safe to call here since we're @MainActor