Przeglądaj źródła

Snoozing fix (#207)

* Update UserNotificationsManager.swift

Glucose notification function changed to fully snooze, i.e. no pop up at all when snoozed, by @TymHuckin.

* Clean up.

---------

Co-authored-by: TymHuckin <92105120+TymHuckin@users.noreply.github.com>
Jon B Mårtensson 2 lat temu
rodzic
commit
296d5b0ab9

+ 15 - 19
FreeAPS/Sources/Services/UserNotifiactions/UserNotificationsManager.swift

@@ -196,7 +196,6 @@ final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, In
 
         ensureCanSendNotification {
             var titles: [String] = []
-
             var notificationAlarm = false
 
             switch self.glucoseStorage.alarm {
@@ -210,32 +209,29 @@ final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, In
                 notificationAlarm = true
             }
 
-            if self.snoozeUntilDate > Date() {
-                titles.append(NSLocalizedString("(Snoozed)", comment: "(Snoozed)"))
-                notificationAlarm = false
-            }
-
             let delta = glucose.count >= 2 ? glucoseValue - (glucose[glucose.count - 2].glucose ?? 0) : nil
-
             let body = self.glucoseText(glucoseValue: glucoseValue, delta: delta, direction: lastGlucose.direction) + self
                 .infoBody()
 
-            titles.append(body)
-
-            let content = UNMutableNotificationContent()
-            content.title = titles.joined(separator: " ")
-            content.body = body
+            if self.snoozeUntilDate > Date() {
+                titles.append(NSLocalizedString("(Snoozed)", comment: "(Snoozed)"))
+                notificationAlarm = false
+            } else {
+                titles.append(body)
+                let content = UNMutableNotificationContent()
+                content.title = titles.joined(separator: " ")
+                content.body = body
+
+                if notificationAlarm {
+                    self.playSoundIfNeeded()
+                    content.sound = .default
+                    content.userInfo[NotificationAction.key] = NotificationAction.snooze.rawValue
+                }
 
-            if notificationAlarm {
-                self.playSoundIfNeeded()
-                content.sound = .default
-                content.userInfo[NotificationAction.key] = NotificationAction.snooze.rawValue
+                self.addRequest(identifier: .glucocoseNotification, content: content, deleteOld: true)
             }
-
-            self.addRequest(identifier: .glucocoseNotification, content: content, deleteOld: true)
         }
     }
-
     private func glucoseText(glucoseValue: Int, delta: Int?, direction: BloodGlucose.Direction?) -> String {
         let units = settingsManager.settings.units
         let glucoseText = glucoseFormatter