Преглед изворни кода

fix bolus cancel message being sent all the time due to bolusprogress being nil most of the time

polscm32 aka Marvout пре 1 година
родитељ
комит
e1a740bedc

+ 0 - 16
Trio Watch App Extension/OverlayState.swift

@@ -1,16 +0,0 @@
-import SwiftUI
-
-class OverlayState: ObservableObject {
-    @Published var isVisible: Bool = false
-    @Published var overlayContent = AnyView(EmptyView()) // Holds the content of the overlay
-
-    func showOverlay<Content: View>(_ content: Content) {
-        overlayContent = AnyView(content)
-        isVisible = true
-    }
-
-    func hideOverlay() {
-        isVisible = false
-        overlayContent = AnyView(EmptyView())
-    }
-}

+ 0 - 10
Trio Watch App Extension/PressableIconButtonStyle.swift

@@ -1,10 +0,0 @@
-import SwiftUI
-
-struct PressableIconButtonStyle: ButtonStyle {
-    func makeBody(configuration: Configuration) -> some View {
-        configuration.label
-            .background(Color.clear)
-            .opacity(configuration.isPressed ? 0.3 : 1.0) // Change opacity when pressed
-            .animation(.easeInOut(duration: 0.25), value: configuration.isPressed) // Smooth transition
-    }
-}

+ 12 - 3
Trio/Sources/Services/WatchManager/AppleWatchManager.swift

@@ -688,20 +688,29 @@ 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 progress == nil {
+                if let progress = progress {
+                    wasBolusActive = true
+                    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
                     debug(.watchManager, "📱 Bolus cancelled from phone")
                     self?.sendBolusCanceledMessageToWatch()
-                } else {
-                    self?.sendBolusProgressToWatch(progress: progress)
                 }
             }
             .store(in: &subscriptions)
     }
 
+    /// Sends bolus progress updates to the Watch
+    /// - Parameter progress: The current bolus progress as a Decimal
     private func sendBolusProgressToWatch(progress: Decimal?) {
         guard let session = session, session.isReachable, let progress = progress else { return }