Browse Source

cancel bolus

polscm32 aka Marvout 1 year ago
parent
commit
1829ac58d9

+ 4 - 1
Trio Watch App Extension/Views/BolusProgressOverlay.swift

@@ -17,7 +17,7 @@ struct BolusProgressOverlay: View {
     )
 
     var body: some View {
-        if state.bolusProgress > 0 && state.bolusProgress < 1.0 {
+        if state.bolusProgress > 0 && state.bolusProgress < 1.0 && !state.isBolusCanceled {
             VStack {
                 Spacer()
                 VStack(spacing: 4) {
@@ -27,6 +27,7 @@ struct BolusProgressOverlay: View {
 
                         Button(action: {
                             state.sendCancelBolusRequest()
+                            state.activeBolusAmount = 0
                             navigationState.resetToRoot()
                         }) {
                             Image(systemName: "xmark.circle.fill")
@@ -48,6 +49,8 @@ struct BolusProgressOverlay: View {
                 .background(Color.black.opacity(0.7))
                 .cornerRadius(10)
                 .padding()
+            }.onDisappear {
+                state.activeBolusAmount = 0
             }
         }
     }

+ 5 - 1
Trio Watch App Extension/WatchState.swift

@@ -31,6 +31,7 @@ import WatchConnectivity
     var confirmationProgress = 0.0
 
     var bolusProgress: Double = 0.0
+    var isBolusCanceled = false
 
     override init() {
         super.init()
@@ -150,6 +151,7 @@ import WatchConnectivity
     }
 
     func sendCancelBolusRequest() {
+        isBolusCanceled = true
         guard let session = session, session.isReachable else { return }
 
         let message: [String: Any] = [
@@ -240,7 +242,9 @@ import WatchConnectivity
             }
 
             if let bolusProgress = message["bolusProgress"] as? Double {
-                self.bolusProgress = bolusProgress
+                if !self.isBolusCanceled {
+                    self.bolusProgress = bolusProgress
+                }
             }
         }
     }

+ 8 - 0
Trio/Sources/Services/WatchManager/AppleWatchManager.swift

@@ -346,6 +346,14 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                 debug(.watchManager, "📱 Received cancel temp target request from watch")
                 self?.handleCancelTempTarget()
             }
+
+            // Handle bolus cancellation
+            if message["cancelBolus"] as? Bool == true {
+                Task {
+                    await self?.apsManager.cancelBolus()
+                    debug(.watchManager, "📱 Bolus cancelled from watch")
+                }
+            }
         }
     }