Procházet zdrojové kódy

Bolus failed notification

Ivan Valkou před 4 roky
rodič
revize
0b6251b7a1

+ 7 - 0
FreeAPS/Sources/APS/APSManager.swift

@@ -305,6 +305,13 @@ final class BaseAPSManager: APSManager, Injectable {
             if case let .failure(error) = completion {
             if case let .failure(error) = completion {
                 warning(.apsManager, "Bolus failed with error: \(error.localizedDescription)")
                 warning(.apsManager, "Bolus failed with error: \(error.localizedDescription)")
                 self.processError(APSError.pumpError(error))
                 self.processError(APSError.pumpError(error))
+                if !isSMB {
+                    self.processQueue.async {
+                        self.broadcaster.notify(BolusFailureObserver.self, on: self.processQueue) {
+                            $0.bolusDidFail()
+                        }
+                    }
+                }
             } else {
             } else {
                 debug(.apsManager, "Bolus succeeded")
                 debug(.apsManager, "Bolus succeeded")
                 if !isSMB {
                 if !isSMB {

+ 6 - 0
FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings

@@ -869,6 +869,12 @@ Enact a temp Basal or a temp target */
 /* About this source */
 /* About this source */
 "About this source" = "About this source";
 "About this source" = "About this source";
 
 
+/* */
+"Bolus failed" = "Bolus failed";
+
+/* */
+"Bolus failed or inaccurate. Check pump history before repeating." = "Bolus failed or inaccurate. Check pump history before repeating.";
+
 
 
 /* Headers for settings ----------------------- */
 /* Headers for settings ----------------------- */
 "OpenAPS main settings" = "OpenAPS main settings";
 "OpenAPS main settings" = "OpenAPS main settings";

+ 6 - 0
FreeAPS/Sources/Localizations/Main/ru.lproj/Localizable.strings

@@ -860,6 +860,12 @@ Enact a temp Basal or a temp target */
 /* About this source */
 /* About this source */
 "About this source" = "Об этом источнике";
 "About this source" = "Об этом источнике";
 
 
+/* */
+"Bolus failed" = "Болюс не выполнен";
+
+/* */
+"Bolus failed or inaccurate. Check pump history before repeating." = "Болюс не выполнен или неточный. Перед повторением проверьте историю помпы.";
+
 
 
 /* Headers for settings ----------------------- */
 /* Headers for settings ----------------------- */
 "OpenAPS main settings" = "Основные настройки OpenAPS";
 "OpenAPS main settings" = "Основные настройки OpenAPS";

+ 34 - 0
FreeAPS/Sources/Services/UserNotifiactions/UserNotificationsManager.swift

@@ -18,12 +18,17 @@ enum NotificationAction: String {
     case snooze
     case snooze
 }
 }
 
 
+protocol BolusFailureObserver {
+    func bolusDidFail()
+}
+
 final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, Injectable {
 final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, Injectable {
     private enum Identifier: String {
     private enum Identifier: String {
         case glucocoseNotification = "FreeAPS.glucoseNotification"
         case glucocoseNotification = "FreeAPS.glucoseNotification"
         case carbsRequiredNotification = "FreeAPS.carbsRequiredNotification"
         case carbsRequiredNotification = "FreeAPS.carbsRequiredNotification"
         case noLoopFirstNotification = "FreeAPS.noLoopFirstNotification"
         case noLoopFirstNotification = "FreeAPS.noLoopFirstNotification"
         case noLoopSecondNotification = "FreeAPS.noLoopSecondNotification"
         case noLoopSecondNotification = "FreeAPS.noLoopSecondNotification"
+        case bolusFailedNotification = "FreeAPS.bolusFailedNotification"
     }
     }
 
 
     @Injected() private var settingsManager: SettingsManager!
     @Injected() private var settingsManager: SettingsManager!
@@ -44,6 +49,7 @@ final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, In
         injectServices(resolver)
         injectServices(resolver)
         broadcaster.register(GlucoseObserver.self, observer: self)
         broadcaster.register(GlucoseObserver.self, observer: self)
         broadcaster.register(SuggestionObserver.self, observer: self)
         broadcaster.register(SuggestionObserver.self, observer: self)
+        broadcaster.register(BolusFailureObserver.self, observer: self)
 
 
         requestNotificationPermissionsIfNeeded()
         requestNotificationPermissionsIfNeeded()
         sendGlucoseNotification()
         sendGlucoseNotification()
@@ -144,6 +150,28 @@ final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, In
         }
         }
     }
     }
 
 
+    private func notifyBolusFailure() {
+        ensureCanSendNotification {
+            let title = NSLocalizedString("Bolus failed", comment: "Bolus failed")
+            let body = NSLocalizedString(
+                "Bolus failed or inaccurate. Check pump history before repeating.",
+                comment: "Bolus failed or inaccurate. Check pump history before repeating."
+            )
+
+            let content = UNMutableNotificationContent()
+            content.title = title
+            content.body = body
+            content.sound = .default
+
+            self.addRequest(
+                identifier: .noLoopFirstNotification,
+                content: content,
+                deleteOld: true,
+                trigger: nil
+            )
+        }
+    }
+
     private func sendGlucoseNotification() {
     private func sendGlucoseNotification() {
         addAppBadge(glucose: nil)
         addAppBadge(glucose: nil)
 
 
@@ -373,6 +401,12 @@ extension BaseUserNotificationsManager: SuggestionObserver {
     }
     }
 }
 }
 
 
+extension BaseUserNotificationsManager: BolusFailureObserver {
+    func bolusDidFail() {
+        notifyBolusFailure()
+    }
+}
+
 extension BaseUserNotificationsManager: UNUserNotificationCenterDelegate {
 extension BaseUserNotificationsManager: UNUserNotificationCenterDelegate {
     func userNotificationCenter(
     func userNotificationCenter(
         _: UNUserNotificationCenter,
         _: UNUserNotificationCenter,