|
|
@@ -4,18 +4,18 @@ import SwiftUI
|
|
|
extension Snooze {
|
|
|
@Observable final class StateModel: BaseStateModel<Provider> {
|
|
|
@ObservationIgnored @Persisted(key: "UserNotificationsManager.snoozeUntilDate") var snoozeUntilDate: Date = .distantPast
|
|
|
- @ObservationIgnored @Injected() var glucoseStogare: GlucoseStorage!
|
|
|
+ @ObservationIgnored @Injected() var glucoseStorage: GlucoseStorage!
|
|
|
@ObservationIgnored @Injected() var notificationsManager: UserNotificationsManager!
|
|
|
@ObservationIgnored @Injected() var broadcaster: Broadcaster!
|
|
|
|
|
|
var alarm: GlucoseAlarm?
|
|
|
|
|
|
override func subscribe() {
|
|
|
- alarm = glucoseStogare.alarm
|
|
|
+ alarm = glucoseStorage.alarm
|
|
|
broadcaster.register(SnoozeObserver.self, observer: self)
|
|
|
}
|
|
|
|
|
|
- deinit {
|
|
|
+ func unsubscribe() {
|
|
|
broadcaster.unregister(SnoozeObserver.self, observer: self)
|
|
|
}
|
|
|
|
|
|
@@ -33,14 +33,14 @@ extension Snooze {
|
|
|
|
|
|
Task { @MainActor in
|
|
|
snoozeUntilDate = Date().addingTimeInterval(duration)
|
|
|
- alarm = glucoseStogare.alarm
|
|
|
+ alarm = glucoseStorage.alarm
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@MainActor func applySnooze(_ duration: TimeInterval) async {
|
|
|
// Allow any duration chosen in the Snooze UI, while keeping validation for quick actions elsewhere.
|
|
|
snoozeUntilDate = duration > 0 ? Date().addingTimeInterval(duration) : .distantPast
|
|
|
- alarm = glucoseStogare.alarm
|
|
|
+ alarm = glucoseStorage.alarm
|
|
|
await notificationsManager.applySnooze(for: duration)
|
|
|
}
|
|
|
}
|
|
|
@@ -50,7 +50,7 @@ extension Snooze.StateModel: SnoozeObserver {
|
|
|
func snoozeDidChange(_ untilDate: Date) {
|
|
|
Task { @MainActor in
|
|
|
snoozeUntilDate = untilDate
|
|
|
- alarm = glucoseStogare.alarm
|
|
|
+ alarm = glucoseStorage.alarm
|
|
|
}
|
|
|
}
|
|
|
}
|