Kaynağa Gözat

Remove bolus progress and reporting for watch app

Deniz Cengiz 1 yıl önce
ebeveyn
işleme
6cd550ab8f

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

@@ -84,7 +84,6 @@ 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
@@ -110,14 +109,5 @@ struct BolusConfirmationView: View {
                 )
             }
         }
-        .blur(radius: state.showBolusProgressOverlay ? 3 : 0)
-        .overlay {
-            if state.showBolusProgressOverlay {
-                BolusProgressOverlay(state: state) {
-                    state.shouldNavigateToRoot = false
-                    navigationPath.append(NavigationDestinations.acknowledgmentPending)
-                }.transition(.opacity)
-            }
-        }
     }
 }

+ 0 - 9
Trio Watch App Extension/Views/BolusInputView.swift

@@ -142,15 +142,6 @@ struct BolusInputView: View {
                     .clipShape(Circle())
             }
         }
-        .blur(radius: state.showBolusProgressOverlay ? 3 : 0)
-        .overlay {
-            if state.showBolusProgressOverlay {
-                BolusProgressOverlay(state: state) {
-                    state.shouldNavigateToRoot = false
-                    navigationPath.append(NavigationDestinations.acknowledgmentPending)
-                }.transition(.opacity)
-            }
-        }
         .onAppear {
             // Set initial bolus amount to recommended value
             // Only do this if user has not updated amount previously, e.g., when navigating to next and then back to this view

+ 86 - 86
Trio Watch App Extension/Views/BolusProgressOverlay.swift

@@ -1,86 +1,86 @@
-import SwiftUI
-
-struct BolusProgressOverlay: View {
-    let state: WatchState
-    let onCancelBolus: () -> Void
-
-    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
-    )
-
-    private var isWatchStateDated: Bool {
-        // If `lastWatchStateUpdate` is nil, treat as "dated"
-        guard let lastUpdateTimestamp = state.lastWatchStateUpdate else {
-            return true
-        }
-        let now = Date().timeIntervalSince1970
-        let secondsSinceUpdate = now - lastUpdateTimestamp
-        // Return true if last update older than 5 min, so 1 loop cycle
-        return secondsSinceUpdate > 5 * 60
-    }
-
-    private var isSessionUnreachable: Bool {
-        guard let session = state.session else {
-            return true // No session at all => unreachable
-        }
-        // Return true if not .activated OR not reachable
-        return session.activationState != .activated
-    }
-
-    var body: some View {
-        VStack(spacing: 10) {
-            VStack {
-                Text("Bolusing")
-                    .font(.footnote)
-                    .foregroundStyle(.secondary)
-                    .padding(.top)
-
-                ProgressView(value: state.bolusProgress, total: 1.0)
-                    .tint(progressGradient)
-
-                Text(String(
-                    format: String(
-                        localized: "%.2f U of %.2f U",
-                        comment: "Format for showing delivered and active bolus amounts, 'x U of y U' on watch"
-                    ),
-                    state.deliveredAmount,
-                    state.activeBolusAmount
-                ))
-                    .font(.footnote)
-                    .foregroundStyle(.secondary)
-
-                Spacer()
-
-                Button(action: {
-                    state.sendCancelBolusRequest()
-                    onCancelBolus()
-                }) {
-                    Text("Cancel Bolus")
-                }
-                .buttonStyle(.bordered)
-                .padding()
-                .disabled(isWatchStateDated || isSessionUnreachable)
-            }
-            .padding()
-            .background(Color.black.opacity(0.9))
-            .cornerRadius(10)
-        }
-        .scenePadding()
-        .onChange(of: state.bolusProgress) { _, newProgress in
-            if newProgress >= 1.0 {
-                state.activeBolusAmount = 0 // Reset only when bolus is complete
-            }
-        }
-        .onDisappear {
-            state.activeBolusAmount = 0 // Triple-check to reset when view disappears
-        }
-    }
-}
+// import SwiftUI
+//
+// struct BolusProgressOverlay: View {
+//    let state: WatchState
+//    let onCancelBolus: () -> Void
+//
+//    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
+//    )
+//
+//    private var isWatchStateDated: Bool {
+//        // If `lastWatchStateUpdate` is nil, treat as "dated"
+//        guard let lastUpdateTimestamp = state.lastWatchStateUpdate else {
+//            return true
+//        }
+//        let now = Date().timeIntervalSince1970
+//        let secondsSinceUpdate = now - lastUpdateTimestamp
+//        // Return true if last update older than 5 min, so 1 loop cycle
+//        return secondsSinceUpdate > 5 * 60
+//    }
+//
+//    private var isSessionUnreachable: Bool {
+//        guard let session = state.session else {
+//            return true // No session at all => unreachable
+//        }
+//        // Return true if not .activated OR not reachable
+//        return session.activationState != .activated
+//    }
+//
+//    var body: some View {
+//        VStack(spacing: 10) {
+//            VStack {
+//                Text("Bolusing")
+//                    .font(.footnote)
+//                    .foregroundStyle(.secondary)
+//                    .padding(.top)
+//
+////                ProgressView(value: state.bolusProgress, total: 1.0)
+//                    .tint(progressGradient)
+//
+//                Text(String(
+//                    format: String(
+//                        localized: "%.2f U of %.2f U",
+//                        comment: "Format for showing delivered and active bolus amounts, 'x U of y U' on watch"
+//                    ),
+//                    state.deliveredAmount,
+//                    state.activeBolusAmount
+//                ))
+//                    .font(.footnote)
+//                    .foregroundStyle(.secondary)
+//
+//                Spacer()
+//
+//                Button(action: {
+//                    state.sendCancelBolusRequest()
+//                    onCancelBolus()
+//                }) {
+//                    Text("Cancel Bolus")
+//                }
+//                .buttonStyle(.bordered)
+//                .padding()
+//                .disabled(isWatchStateDated || isSessionUnreachable)
+//            }
+//            .padding()
+//            .background(Color.black.opacity(0.9))
+//            .cornerRadius(10)
+//        }
+//        .scenePadding()
+//        .onChange(of: state.bolusProgress) { _, newProgress in
+//            if newProgress >= 1.0 {
+//                state.activeBolusAmount = 0 // Reset only when bolus is complete
+//            }
+//        }
+//        .onDisappear {
+//            state.activeBolusAmount = 0 // Triple-check to reset when view disappears
+//        }
+//    }
+// }

+ 1 - 13
Trio Watch App Extension/Views/TrioMainWatchView.swift

@@ -96,10 +96,7 @@ struct TrioMainWatchView: View {
                 .tag(1)
             }
             .onAppear {
-                // Hard reset variables when main view appears
-                /// Reset `bolusProgress` and `activeBolusAmount` to ensure no stale bolus progressbar is stuck on home view
-                state.bolusProgress = 0
-                state.activeBolusAmount = 0
+                /// Hard reset variables when main view appears
                 /// Reset `bolusAmount` and `recommendedBolus` to ensure no stale / old value is set when user opens bolus input or meal combo the next time.
                 state.bolusAmount = 0
                 state.recommendedBolus = 0
@@ -226,15 +223,6 @@ struct TrioMainWatchView: View {
             }
         }
         .ignoresSafeArea()
-        .blur(radius: state.showBolusProgressOverlay ? 3 : 0)
-        .overlay {
-            if state.showBolusProgressOverlay {
-                BolusProgressOverlay(state: state) {
-                    state.shouldNavigateToRoot = false
-                    navigationPath.append(NavigationDestinations.acknowledgmentPending)
-                }.transition(.opacity)
-            }
-        }
     }
 
     private func updateRotation(for trend: String?) {

+ 1 - 11
Trio Watch App Extension/WatchState+Requests.swift

@@ -14,10 +14,9 @@ extension WatchState {
         }
 
         isBolusCanceled = false // Reset canceled state when starting new bolus
-        activeBolusAmount = Double(truncating: amount as NSNumber) // Set active bolus amount
 
         WatchLogger.shared.log("⌚️ Sending bolus request: \(amount)U")
-        WatchLogger.shared.log("⌚️ isBolusCanceled = false, activeBolusAmount = \(activeBolusAmount)")
+        WatchLogger.shared.log("⌚️ isBolusCanceled = false")
 
         let message: [String: Any] = [
             WatchMessageKeys.bolus: amount
@@ -157,7 +156,6 @@ extension WatchState {
         }
 
         WatchLogger.shared.log("⌚️ Sending cancel bolus request. bolusCanceled = true")
-        WatchLogger.shared.log("⌚️ Resetting bolusProgress and activeBolusAmount to 0")
 
         let message: [String: Any] = [
             WatchMessageKeys.cancelBolus: true
@@ -167,11 +165,6 @@ extension WatchState {
             WatchLogger.shared.log("Error sending cancel bolus request: \(error.localizedDescription)")
         }
 
-        // Reset when cancelled
-        bolusProgress = 0
-        activeBolusAmount = 0
-        WatchLogger.shared.log("⌚️ reset bolusProgress and activeBolusAmount to 0")
-
         // Display pending communication animation
         showCommsAnimation = true
         WatchLogger.shared.log("⌚️ showCommsAnimation = true")
@@ -194,9 +187,6 @@ extension WatchState {
         session.sendMessage(message, replyHandler: nil) { error in
             WatchLogger.shared.log("Error requesting bolus recommendation: \(error.localizedDescription)")
         }
-
-        showBolusCalculationProgress = true
-        WatchLogger.shared.log("⌚️ showBolusCalculationProgress = true")
     }
 
     func requestWatchStateUpdate() {

+ 4 - 60
Trio Watch App Extension/WatchState.swift

@@ -36,9 +36,9 @@ import WatchConnectivity
     var bolusAmount: Double = 0.0
     var confirmationProgress: Double = 0.0
 
-    var bolusProgress: Double = 0.0
-    var activeBolusAmount: Double = 0.0
-    var deliveredAmount: Double = 0.0
+//    var bolusProgress: Double = 0.0
+//    var activeBolusAmount: Double = 0.0
+//    var deliveredAmount: Double = 0.0
     var isBolusCanceled = false
 
     // Safety limits
@@ -65,13 +65,9 @@ import WatchConnectivity
     var mealBolusStep: MealBolusStep = .savingCarbs
     var isMealBolusCombo: Bool = false
 
-    var showBolusProgressOverlay: Bool {
-        (!showAcknowledgmentBanner || !showCommsAnimation) && bolusProgress > 0 && bolusProgress < 1.0 && !isBolusCanceled
-    }
-
     var recommendedBolus: Decimal = 0
 
-    // Debouncing and batch processing helpers
+    // MARK: - Debouncing and batch processing helpers
 
     /// Temporary storage for new data arriving via WatchConnectivity.
     private var pendingData: [String: Any] = [:]
@@ -202,47 +198,6 @@ import WatchConnectivity
             }
 
             return
-
-                    // Handle bolus progress updates
-        } else if
-            let timestamp = message[WatchMessageKeys.bolusProgressTimestamp] as? TimeInterval,
-            let progress = message[WatchMessageKeys.bolusProgress] as? Double,
-            let activeBolusAmount = message[WatchMessageKeys.activeBolusAmount] as? Double,
-            let deliveredAmount = message[WatchMessageKeys.deliveredAmount] as? Double
-        {
-            let date = Date(timeIntervalSince1970: timestamp)
-
-            // Check if it's not older than 5 min
-            if date >= Date().addingTimeInterval(-5 * 60) {
-                WatchLogger.shared.log("⌚️ Handling bolusProgress (sent at \(date))")
-                DispatchQueue.main.async {
-                    if !self.isBolusCanceled {
-                        self.bolusProgress = progress
-                        self.activeBolusAmount = activeBolusAmount
-                        self.deliveredAmount = deliveredAmount
-                    }
-                }
-            } else {
-                WatchLogger.shared.log("⌚️ Received outdated bolus progress (sent at \(date))")
-                DispatchQueue.main.async {
-                    self.bolusProgress = 0
-                    self.activeBolusAmount = 0
-                }
-            }
-            return
-
-                    // Handle bolus cancellation
-        } else if
-            message[WatchMessageKeys.bolusCanceled] as? Bool == true
-        {
-            DispatchQueue.main.async {
-                self.bolusProgress = 0
-                self.activeBolusAmount = 0
-                self
-                    .isBolusCanceled =
-                    false /// Reset flag to ensure a bolus progress is also shown after canceling bolus from watch
-            }
-            return
         } else {
             WatchLogger.shared.log("⌚️ Faulty data. Skipping...")
             DispatchQueue.main.async {
@@ -511,17 +466,6 @@ import WatchConnectivity
             }
         }
 
-        if let bolusProgress = message[WatchMessageKeys.bolusProgress] as? Double {
-            if !isBolusCanceled {
-                self.bolusProgress = bolusProgress
-            }
-        }
-
-        if let bolusWasCanceled = message[WatchMessageKeys.bolusCanceled] as? Bool, bolusWasCanceled {
-            bolusProgress = 0
-            activeBolusAmount = 0
-        }
-
         if let maxBolusValue = message[WatchMessageKeys.maxBolus] {
             if let decimalValue = (maxBolusValue as? NSNumber)?.decimalValue {
                 maxBolus = decimalValue

+ 2 - 0
Trio/Sources/Localizations/Main/Localizable.xcstrings

@@ -6383,6 +6383,7 @@
     },
     "%.2f U of %.2f U" : {
       "comment" : "Format for showing delivered and active bolus amounts, 'x U of y U' on watch",
+      "extractionState" : "stale",
       "localizations" : {
         "bg" : {
           "stringUnit" : {
@@ -48553,6 +48554,7 @@
       }
     },
     "Cancel Bolus" : {
+      "extractionState" : "stale",
       "localizations" : {
         "bg" : {
           "stringUnit" : {

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

@@ -77,7 +77,6 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
             .store(in: &subscriptions)
 
         registerHandlers()
-        subscribeToBolusProgress()
     }
 
     private func registerHandlers() {
@@ -971,73 +970,6 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
             }
         }
     }
-
-    /// Subscribes to bolus progress updates and sends progress or cancellation messages to the Watch
-    private func subscribeToBolusProgress() {
-        var wasBolusActive = false
-
-        apsManager.bolusProgress
-            .receive(on: DispatchQueue.main)
-            .sink { [weak self] progress in
-                if let progress = progress {
-                    wasBolusActive = true
-                    Task {
-                        await self?.sendBolusProgressToWatch(progress: progress)
-                    }
-                } else if wasBolusActive {
-                    // Only if a bolus was previously active and now nil is received,
-                    // the bolus was cancelled
-                    wasBolusActive = false
-                    self?.activeBolusAmount = 0.0
-
-                    debug(.watchManager, "📱 Bolus cancelled from phone")
-                    self?.sendBolusCanceledMessageToWatch()
-                }
-            }
-            .store(in: &subscriptions)
-    }
-
-    /// Sends bolus progress updates to the Watch
-    /// - Parameter progress: The current bolus progress as a Decimal
-    private func sendBolusProgressToWatch(progress: Decimal?) async {
-        guard let session = session, let progress = progress, let pumpManager = apsManager.pumpManager else { return }
-
-        let message: [String: Any] = [
-            WatchMessageKeys.bolusProgressTimestamp: Date().timeIntervalSince1970,
-            WatchMessageKeys.bolusProgress: Double(truncating: progress as NSNumber),
-            WatchMessageKeys.activeBolusAmount: activeBolusAmount,
-            WatchMessageKeys.deliveredAmount: pumpManager
-                .roundToSupportedBolusVolume(units: activeBolusAmount * Double(truncating: progress as NSNumber))
-        ]
-        // If the session is not yet activated, try to activate
-        if session.activationState != .activated {
-            session.activate()
-            // Then, queue data for eventual delivery in the background
-//            session.transferUserInfo(message)
-            return
-        }
-
-        // If we reach here, session should be .activated
-        if session.isReachable {
-            // Real-time ephemeral
-            session.sendMessage(message, replyHandler: nil) { error in
-                debug(.watchManager, "❌ Error sending bolus progress: \(error.localizedDescription)")
-            }
-        }
-//        else {
-//            // Fallback to be double safe: queue userInfo for eventual delivery
-//            session.transferUserInfo(message)
-//        }
-    }
-
-    private func sendBolusCanceledMessageToWatch() {
-        if let session = session, session.isReachable {
-            let message: [String: Any] = [WatchMessageKeys.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?