polscm32 aka Marvout 1 år sedan
förälder
incheckning
199e22a88b

+ 1 - 0
Trio Watch App Extension/Views/BolusConfirmationView.swift

@@ -73,6 +73,7 @@ struct BolusConfirmationView: View {
                         state.sendCarbsRequest(state.carbsAmount, Date())
                         state.carbsAmount = 0 // reset carbs in state
                     }
+                    state.activeBolusAmount = bolusAmount
                     state.sendBolusRequest(Decimal(bolusAmount))
                     bolusAmount = 0 // reset bolus in state
                     confirmationProgress = 0 // reset auth progress

+ 54 - 0
Trio Watch App Extension/Views/BolusProgressOverlay.swift

@@ -0,0 +1,54 @@
+import SwiftUI
+
+struct BolusProgressOverlay: View {
+    let state: WatchState
+    @ObservedObject var navigationState: NavigationState
+
+    private let progressGradient = LinearGradient(
+        colors: [
+            Color(red: 0.7215686275, green: 0.3411764706, blue: 1), // #B857FF
+            Color(red: 0.6235294118, green: 0.4235294118, blue: 0.9803921569), // #9F6CFA
+            Color(red: 0.4862745098, green: 0.5450980392, blue: 0.9529411765), // #7C8BF3
+            Color(red: 0.3411764706, green: 0.6666666667, blue: 0.9254901961), // #57AAEC
+            Color(red: 0.262745098, green: 0.7333333333, blue: 0.9137254902) // #43BBE9
+        ],
+        startPoint: .leading,
+        endPoint: .trailing
+    )
+
+    var body: some View {
+        if state.bolusProgress > 0 && state.bolusProgress < 1.0 {
+            VStack {
+                Spacer()
+                VStack(spacing: 4) {
+                    HStack {
+                        ProgressView(value: state.bolusProgress, total: 1.0)
+                            .tint(progressGradient)
+
+                        Button(action: {
+                            state.sendCancelBolusRequest()
+                            navigationState.resetToRoot()
+                        }) {
+                            Image(systemName: "xmark.circle.fill")
+                                .foregroundStyle(.red)
+                                .font(.system(size: 20))
+                        }
+                        .buttonStyle(.plain)
+                    }
+
+                    Text(String(
+                        format: "%.1f U of %.1f U",
+                        state.bolusProgress * state.activeBolusAmount,
+                        state.activeBolusAmount
+                    ))
+                        .font(.caption2)
+                        .foregroundStyle(.secondary)
+                }
+                .padding()
+                .background(Color.black.opacity(0.7))
+                .cornerRadius(10)
+                .padding()
+            }
+        }
+    }
+}

+ 3 - 0
Trio Watch App Extension/Views/TrioMainWatchView.swift

@@ -146,6 +146,9 @@ struct TrioMainWatchView: View {
                     )
                 }
             }
+            .overlay(
+                BolusProgressOverlay(state: state, navigationState: navigationState)
+            )
         }
     }
 

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

@@ -27,8 +27,11 @@ import WatchConnectivity
     var fatAmount: Int = 0
     var proteinAmount: Int = 0
     var bolusAmount = 0.0
+    var activeBolusAmount = 0.0
     var confirmationProgress = 0.0
 
+    var bolusProgress: Double = 0.0
+
     override init() {
         super.init()
         setupSession()
@@ -146,6 +149,18 @@ import WatchConnectivity
         }
     }
 
+    func sendCancelBolusRequest() {
+        guard let session = session, session.isReachable else { return }
+
+        let message: [String: Any] = [
+            "cancelBolus": true
+        ]
+
+        session.sendMessage(message, replyHandler: nil) { error in
+            print("Error sending cancel bolus request: \(error.localizedDescription)")
+        }
+    }
+
     // MARK: - WCSessionDelegate
 
     /// Called when the session has completed activation
@@ -223,6 +238,10 @@ import WatchConnectivity
                     return TempTargetPresetWatch(name: name, isEnabled: isEnabled)
                 }
             }
+
+            if let bolusProgress = message["bolusProgress"] as? Double {
+                self.bolusProgress = bolusProgress
+            }
         }
     }
 

+ 4 - 0
Trio.xcodeproj/project.pbxproj

@@ -286,6 +286,7 @@
 		B958F1B72BA0711600484851 /* MKRingProgressView in Frameworks */ = {isa = PBXBuildFile; productRef = B958F1B62BA0711600484851 /* MKRingProgressView */; };
 		B9CAAEFC2AE70836000F68BC /* branch.txt in Resources */ = {isa = PBXBuildFile; fileRef = B9CAAEFB2AE70836000F68BC /* branch.txt */; };
 		BA00D96F7B2FF169A06FB530 /* CGMStateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C018D1680307A31C9ED7120 /* CGMStateModel.swift */; };
+		BD04ECCE2D29952A008C5FEB /* BolusProgressOverlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD04ECCD2D299522008C5FEB /* BolusProgressOverlay.swift */; };
 		BD0B2EF32C5998E600B3298F /* MealPresetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD0B2EF22C5998E600B3298F /* MealPresetView.swift */; };
 		BD1661312B82ADAB00256551 /* CustomProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD1661302B82ADAB00256551 /* CustomProgressView.swift */; };
 		BD2B464E0745FBE7B79913F4 /* NightscoutConfigProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BF768BD6264FF7D71D66767 /* NightscoutConfigProvider.swift */; };
@@ -992,6 +993,7 @@
 		B9B5C0607505A38F256BF99A /* CGMDataFlow.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = CGMDataFlow.swift; sourceTree = "<group>"; };
 		B9CAAEFB2AE70836000F68BC /* branch.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = branch.txt; sourceTree = SOURCE_ROOT; };
 		BA49538D56989D8DA6FCF538 /* TargetsEditorDataFlow.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = TargetsEditorDataFlow.swift; sourceTree = "<group>"; };
+		BD04ECCD2D299522008C5FEB /* BolusProgressOverlay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BolusProgressOverlay.swift; sourceTree = "<group>"; };
 		BD0B2EF22C5998E600B3298F /* MealPresetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MealPresetView.swift; sourceTree = "<group>"; };
 		BD1661302B82ADAB00256551 /* CustomProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomProgressView.swift; sourceTree = "<group>"; };
 		BD1CF8B72C1A4A8400CB930A /* ConfigOverride.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigOverride.xcconfig; sourceTree = "<group>"; };
@@ -2474,6 +2476,7 @@
 		BDA25F1A2D26BCE800035F34 /* Views */ = {
 			isa = PBXGroup;
 			children = (
+				BD04ECCD2D299522008C5FEB /* BolusProgressOverlay.swift */,
 				DD8262CA2D289297009F6F62 /* BolusConfirmationView.swift */,
 				BDA25F212D26D62200035F34 /* BolusInputView.swift */,
 				BDA25F1F2D26D5FB00035F34 /* CarbsInputView.swift */,
@@ -3985,6 +3988,7 @@
 				DD8262CB2D289297009F6F62 /* BolusConfirmationView.swift in Sources */,
 				BD54A9712D281A8100F9C1EE /* TempTargetPresetsView.swift in Sources */,
 				BDA25EE62D260D5E00035F34 /* WatchState.swift in Sources */,
+				BD04ECCE2D29952A008C5FEB /* BolusProgressOverlay.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

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

@@ -56,6 +56,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
             .store(in: &subscriptions)
 
         registerHandlers()
+        subscribeToBolusProgress()
     }
 
     private func registerHandlers() {
@@ -622,4 +623,23 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
             }
         }
     }
+
+    private func subscribeToBolusProgress() {
+        apsManager.bolusProgress
+            .receive(on: DispatchQueue.main)
+            .sink { [weak self] progress in
+                self?.sendBolusProgressToWatch(progress: progress)
+            }
+            .store(in: &subscriptions)
+    }
+
+    private func sendBolusProgressToWatch(progress: Decimal?) {
+        guard let session = session, session.isReachable, let progress = progress else { return }
+
+        let message: [String: Any] = ["bolusProgress": Double(truncating: progress as NSNumber)]
+
+        session.sendMessage(message, replyHandler: nil) { error in
+            debug(.watchManager, "❌ Error sending bolus progress: \(error.localizedDescription)")
+        }
+    }
 }