Преглед на файлове

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

Trio Build Bot преди 1 месец
родител
ревизия
84d8d8e5c1
променени са 2 файла, в които са добавени 3 реда и са изтрити 5 реда
  1. 2 4
      Trio/Sources/Modules/Snooze/SnoozeStateModel.swift
  2. 1 1
      Trio/Sources/Services/UserNotifications/UserNotificationsManager.swift

+ 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