polscm32 aka Marvout 1 rok temu
rodzic
commit
a60cb2c010

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

@@ -49,7 +49,6 @@ import WatchConnectivity
     /// Sends a bolus insulin request to the paired iPhone
     /// - Parameters:
     ///   - amount: The insulin amount to be delivered
-    ///   - isExternal: Indicates if the bolus is from an external source
     func sendBolusRequest(_ amount: Decimal) {
         guard let session = session, session.isReachable else { return }
 

+ 2 - 42
Trio/Sources/Services/WatchManager/AppleWatchManager.swift

@@ -297,15 +297,9 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
 
     func session(_: WCSession, didReceiveMessage message: [String: Any]) {
         DispatchQueue.main.async { [weak self] in
-            if let bolusAmount = message["bolus"] as? Double,
-               let isExternal = message["isExternal"] as? Bool
+            if let bolusAmount = message["bolus"] as? Double
             {
-                print("📱 Received \(isExternal ? "external insulin" : "bolus") request from watch: \(bolusAmount)U")
-                if isExternal {
-                    self?.handleExternalInsulin(Decimal(bolusAmount))
-                } else {
-                    self?.handleBolusRequest(Decimal(bolusAmount))
-                }
+                self?.handleBolusRequest(Decimal(bolusAmount))
             }
 
             if let carbsAmount = message["carbs"] as? Int,
@@ -362,40 +356,6 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
         }
     }
 
-    /// Handles external insulin entries received from the Watch
-    /// - Parameter amount: The insulin amount in units to be recorded
-    private func handleExternalInsulin(_ amount: Decimal) {
-        Task {
-            let context = CoreDataStack.shared.newTaskContext()
-
-            await context.perform {
-                // Create Bolus
-                let bolus = BolusStored(context: context)
-                bolus.amount = amount as NSDecimalNumber
-                bolus.isSMB = false
-                bolus.isExternal = true
-
-                // Create PumpEvent
-                let pumpEvent = PumpEventStored(context: context)
-                pumpEvent.id = UUID().uuidString
-                pumpEvent.timestamp = Date()
-                pumpEvent.type = PumpEvent.bolus.rawValue
-                pumpEvent.bolus = bolus
-                pumpEvent.isUploadedToNS = false
-                pumpEvent.isUploadedToHealth = false
-                pumpEvent.isUploadedToTidepool = false
-
-                do {
-                    guard context.hasChanges else { return }
-                    try context.save()
-                    print("📱 Saved external insulin and pump event from watch: \(amount)U")
-                } catch {
-                    print("❌ Error saving external insulin and pump event: \(error.localizedDescription)")
-                }
-            }
-        }
-    }
-
     /// Processes bolus requests received from the Watch
     /// - Parameter amount: The requested bolus amount in units
     private func handleBolusRequest(_ amount: Decimal) {