Jelajahi Sumber

fix bolus progress overlay being stuck on watch when cancelling bolus via phone

polscm32 aka Marvout 1 tahun lalu
induk
melakukan
8d9bec74d9

+ 6 - 0
Trio Watch App Extension/WatchState.swift

@@ -332,6 +332,12 @@ import WatchConnectivity
                 }
             }
 
+            if let bolusWasCanceled = message["bolusCanceled"] as? Bool, bolusWasCanceled {
+                self.bolusProgress = 0
+                self.activeBolusAmount = 0
+                return
+            }
+
             // Debug print für die Safety Limits
             if let maxBolusValue = message["maxBolus"] {
                 print("⌚️ Received maxBolus: \(maxBolusValue) of type \(type(of: maxBolusValue))")

+ 18 - 1
Trio/Sources/Services/WatchManager/AppleWatchManager.swift

@@ -386,6 +386,9 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                 Task {
                     await self?.apsManager.cancelBolus()
                     debug(.watchManager, "📱 Bolus cancelled from watch")
+
+                    // perform determine basal sync, otherwise you have could end up with too much iob when opening the calculator again
+                    await self?.apsManager.determineBasalSync()
                 }
             }
         }
@@ -689,7 +692,12 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
         apsManager.bolusProgress
             .receive(on: DispatchQueue.main)
             .sink { [weak self] progress in
-                self?.sendBolusProgressToWatch(progress: progress)
+                if progress == nil {
+                    debug(.watchManager, "📱 Bolus cancelled from phone")
+                    self?.sendBolusCanceledMessageToWatch()
+                } else {
+                    self?.sendBolusProgressToWatch(progress: progress)
+                }
             }
             .store(in: &subscriptions)
     }
@@ -703,6 +711,15 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
             debug(.watchManager, "❌ Error sending bolus progress: \(error.localizedDescription)")
         }
     }
+
+    private func sendBolusCanceledMessageToWatch() {
+        if let session = session, session.isReachable {
+            let message: [String: Any] = ["bolusCanceled": true]
+            session.sendMessage(message, replyHandler: nil) { error in
+                debug(.watchManager, "❌ Error sending bolus cancellation to watch: \(error.localizedDescription)")
+            }
+        }
+    }
 }
 
 // TODO: - is there a better approach than setting up the watch state every time a setting has changed?