Explorar el Código

Display errorPump as APNs instead of custom router.alertMessage

kskandis hace 1 año
padre
commit
d4d97485c3

+ 0 - 10
FreeAPS/Sources/APS/DeviceDataManager.swift

@@ -648,15 +648,6 @@ extension BaseDeviceDataManager: AlertObserver {
     }
 
     private func ackAlert(alert: AlertEntry) {
-        let typeMessage: MessageType
-        let alertUp = alert.alertIdentifier.uppercased()
-        if alertUp.contains("FAULT") || alertUp.contains("ERROR") {
-            typeMessage = .errorPump
-        } else {
-            typeMessage = .warning
-        }
-
-        let messageCont = MessageContent(content: alert.contentBody ?? "Unknown", type: typeMessage)
         let alertIssueDate = alert.issuedDate
 
         processQueue.async {
@@ -676,7 +667,6 @@ extension BaseDeviceDataManager: AlertObserver {
             }
 
             self.pumpManager?.acknowledgeAlert(alertIdentifier: alert.alertIdentifier) { error in
-                self.router.alertMessage.send(messageCont)
                 if let error = error {
                     self.alertHistoryStorage.ackAlert(alertIssueDate, error.localizedDescription)
                     debug(.deviceManager, "acknowledge not succeeded with error \(error.localizedDescription)")

+ 18 - 3
FreeAPS/Sources/Modules/Main/MainStateModel.swift

@@ -79,12 +79,27 @@ extension Main {
                                 self.router.mainSecondaryModalView.send(view)
                             }
                         }
+                    case .pumpConfig:
+                        titleContent = ""
+                        if let pump = self.provider.deviceManager.pumpManager,
+                           let bluetooth = self.provider.bluetoothProvider
+                        {
+                            let view = PumpConfig.PumpSettingsView(
+                                pumpManager: pump,
+                                bluetoothManager: bluetooth,
+                                completionDelegate: self
+                            ).asAny()
+                            self.router.mainSecondaryModalView.send(view)
+                        }
                     }
 
-                    view.titleLabel?.text = titleContent
-                    config.dimMode = .gray(interactive: true)
+                    if message.type != .pumpConfig
+                    {
+                        view.titleLabel?.text = titleContent
+                        config.dimMode = .gray(interactive: true)
 
-                    SwiftMessages.show(config: config, view: view)
+                        SwiftMessages.show(config: config, view: view)
+                    }
                 }
                 .store(in: &lifetime)
 

+ 1 - 0
FreeAPS/Sources/Router/Router.swift

@@ -6,6 +6,7 @@ enum MessageType {
     case info
     case warning
     case errorPump
+    case pumpConfig
 }
 
 struct MessageContent {

+ 15 - 2
FreeAPS/Sources/Services/UserNotifications/UserNotificationsManager.swift

@@ -20,6 +20,7 @@ enum NotificationAction: String {
     static let key = "action"
 
     case snooze
+    case pumpConfig
 }
 
 protocol BolusFailureObserver {
@@ -467,6 +468,10 @@ extension BaseUserNotificationsManager: pumpNotificationObserver {
     func pumpNotification(alert: AlertEntry) {
         ensureCanSendNotification {
             let content = UNMutableNotificationContent()
+            let alertUp = alert.alertIdentifier.uppercased()
+            if alertUp.contains("FAULT") || alertUp.contains("ERROR") {
+                content.userInfo[NotificationAction.key] = NotificationAction.pumpConfig.rawValue
+            }
             content.title = alert.contentTitle ?? "Unknown"
             content.body = alert.contentBody ?? "Unknown"
             content.sound = .default
@@ -504,10 +509,15 @@ extension BaseUserNotificationsManager: BolusFailureObserver {
 extension BaseUserNotificationsManager: UNUserNotificationCenterDelegate {
     func userNotificationCenter(
         _: UNUserNotificationCenter,
-        willPresent _: UNNotification,
+        willPresent notification: UNNotification,
         withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
     ) {
-        completionHandler([.banner, .badge, .sound])
+        switch notification.request.identifier {
+        case Identifier.pumpNotification.rawValue:
+            completionHandler([.banner, .badge, .sound, .list])
+        default:
+            completionHandler([.banner, .badge, .sound])
+        }
     }
 
     func userNotificationCenter(
@@ -523,6 +533,9 @@ extension BaseUserNotificationsManager: UNUserNotificationCenterDelegate {
         switch action {
         case .snooze:
             router.mainModalScreen.send(.snooze)
+        case .pumpConfig:
+            let messageCont = MessageContent(content: response.notification.request.content.body, type: MessageType.pumpConfig)
+            router.alertMessage.send(messageCont)
         }
     }
 }