Przeglądaj źródła

pull in latest changes, solve merge conflicts

polscm32 aka Marvout 1 rok temu
rodzic
commit
d7de0cb39a

+ 16 - 13
Trio Watch App Extension/Views/BolusConfirmationView.swift

@@ -3,11 +3,10 @@ import SwiftUI
 import WatchKit
 
 struct BolusConfirmationView: View {
-    @Environment(\.dismiss) var dismiss
-
-    let bolusAmount: Double
-    @Binding var progress: Double
+    @ObservedObject var navigationState: NavigationState
     let state: WatchState
+    @Binding var bolusAmount: Double
+    @Binding var confirmationProgress: Double
 
     @FocusState private var isCrownFocused: Bool
 
@@ -20,7 +19,7 @@ struct BolusConfirmationView: View {
                     HStack {
                         Text("Carbs:")
                         Spacer()
-                        Text(String(format: "%.1f g", state.carbsAmount))
+                        Text("\(state.carbsAmount) g")
                             .bold()
                             .foregroundStyle(.orange)
                     }.padding(.horizontal)
@@ -35,8 +34,8 @@ struct BolusConfirmationView: View {
                 }.padding(.horizontal)
             }
 
-            ProgressView(value: progress, total: 1.0)
-                .tint(progress >= 1.0 ? .green : .gray)
+            ProgressView(value: confirmationProgress, total: 1.0)
+                .tint(confirmationProgress >= 1.0 ? .green : .gray)
                 .padding(.horizontal)
 
             Spacer()
@@ -45,16 +44,16 @@ struct BolusConfirmationView: View {
                 if state.carbsAmount > 0 {
                     state.carbsAmount = 0 // reset carbs in state
                 }
-                dismiss()
+                bolusAmount = 0 // reset bolus in state
+                confirmationProgress = 0 // reset auth progress
+                navigationState.resetToRoot()
             }
             .buttonStyle(.bordered)
-            .tint(.blue)
-            .disabled(!(bolusAmount > 0.0))
         }
         .focusable(true)
         .focused($isCrownFocused)
         .digitalCrownRotation(
-            $progress,
+            $confirmationProgress,
             from: 0.0,
             through: 1.0,
             by: 0.05,
@@ -65,7 +64,7 @@ struct BolusConfirmationView: View {
         .onAppear {
             isCrownFocused = true
         }
-        .onChange(of: progress) { _, newValue in
+        .onChange(of: confirmationProgress) { _, newValue in
             if newValue >= 1.0 {
                 WKInterfaceDevice.current().play(.success)
 
@@ -75,7 +74,11 @@ struct BolusConfirmationView: View {
                         state.carbsAmount = 0 // reset carbs in state
                     }
                     state.sendBolusRequest(Decimal(bolusAmount))
-                    dismiss()
+                    bolusAmount = 0 // reset bolus in state
+                    confirmationProgress = 0 // reset auth progress
+                    navigationState.resetToRoot()
+
+                    // TODO: add a fancy success animation
                 }
             } else if newValue > 0 {
                 WKInterfaceDevice.current().play(.click)

+ 6 - 12
Trio Watch App Extension/Views/BolusInputView.swift

@@ -5,9 +5,9 @@ import WatchKit
 // MARK: - Bolus Input View
 
 struct BolusInputView: View {
+    @ObservedObject var navigationState: NavigationState
     @State private var bolusAmount = 0.0
     @State private var navigateToConfirmation = false
-    @State private var confirmationProgress = 0.0
 
     let state: WatchState
 
@@ -18,7 +18,7 @@ struct BolusInputView: View {
             if state.carbsAmount > 0 {
                 HStack {
                     Text("Carbs:").bold().font(.subheadline).padding(.leading)
-                    Text(String(format: "%.0f g", state.carbsAmount)).font(.subheadline).foregroundStyle(Color.orange)
+                    Text("\(state.carbsAmount) g").font(.subheadline).foregroundStyle(Color.orange)
                     Spacer()
                 }
             }
@@ -61,7 +61,7 @@ struct BolusInputView: View {
                 // TODO: introduce maxBolus here, disable button if bolusAmount > maxBolus
                 // "+" Button
                 Button(action: {
-                    bolusAmount += 1
+                    bolusAmount += 0.5
                 }) {
                     Image(systemName: "plus.circle.fill")
                         .font(.title3)
@@ -78,7 +78,8 @@ struct BolusInputView: View {
             Spacer()
 
             Button("Log Bolus") {
-                navigateToConfirmation = true
+                state.bolusAmount = bolusAmount
+                navigationState.path.append(NavigationDestinations.bolusConfirm)
             }
             .buttonStyle(.bordered)
             .tint(.blue)
@@ -96,16 +97,9 @@ struct BolusInputView: View {
                     .clipShape(Circle())
             }
         }
-        .navigationDestination(isPresented: $navigateToConfirmation) {
-            BolusConfirmationView(
-                bolusAmount: bolusAmount,
-                progress: $confirmationProgress,
-                state: state
-            )
-        }
     }
 }
 
 #Preview {
-    BolusInputView(state: WatchState())
+    BolusInputView(navigationState: NavigationState(), state: WatchState())
 }

+ 5 - 6
Trio Watch App Extension/Views/CarbsInputView.swift

@@ -4,7 +4,7 @@ import SwiftUI
 // MARK: - Carbs Input View
 
 struct CarbsInputView: View {
-    @Environment(\.dismiss) var dismiss
+    @ObservedObject var navigationState: NavigationState
     @State private var carbsAmount: Double = 0.0 // Needs to be Double due to .digitalCrownRotation() stride
     @State private var navigateToBolus = false // Track navigation to BolusInputView
     @FocusState private var isCrownFocused: Bool // Manage crown focus
@@ -74,10 +74,12 @@ struct CarbsInputView: View {
             Button(buttonLabel) {
                 if continueToBolus {
                     state.carbsAmount = Int(carbsAmount)
-                    navigateToBolus = true
+                    navigationState.path.append(NavigationDestinations.bolusInput)
                 } else {
                     state.sendCarbsRequest(Int(carbsAmount))
-                    dismiss()
+
+                    // TODO: add a fancy success animation
+                    navigationState.resetToRoot()
                 }
             }
             .buttonStyle(.bordered)
@@ -96,8 +98,5 @@ struct CarbsInputView: View {
                     .clipShape(Circle())
             }
         }
-        .navigationDestination(isPresented: $navigateToBolus) {
-            BolusInputView(state: state) // Navigate to BolusInputView
-        }
     }
 }

+ 3 - 3
Trio Watch App Extension/Views/GlucoseChartView.swift

@@ -66,19 +66,19 @@ struct GlucoseChartView: View {
             .chartXAxis {
                 AxisMarks(values: .automatic(desiredCount: 4)) { _ in
                     AxisValueLabel(format: .dateTime.hour())
-                        .font(.system(.caption2, design: .rounded))
+                        .font(.footnote)
                 }
             }
             .chartYAxis {
                 AxisMarks(position: .leading) { value in
                     AxisValueLabel {
                         if let glucose = value.as(Double.self) {
-                            Text("\(Int(glucose))")
-                                .font(.system(.caption2, design: .rounded))
+                            Text("\(Int(glucose))").font(.footnote)
                         }
                     }
                 }
             }
+            .padding()
         }
         .onTapGesture {
             withAnimation {

+ 8 - 2
Trio Watch App Extension/Views/TreatmentMenuView.swift

@@ -3,8 +3,14 @@ import SwiftUI
 struct TreatmentMenuView: View {
     @Environment(\.dismiss) var dismiss
     @Binding var selectedTreatment: TreatmentOption?
+    var onSelect: () -> Void // Callback to handle selection and dismiss the sheet
 
-    let treatments = TreatmentOption.allCases
+    // Define in array to achieve custom order of treatment options
+    let treatments: [TreatmentOption] = [
+        .meal, // First
+        .bolus, // Second
+        .mealBolusCombo // Third
+    ]
 
     private var is40mm: Bool {
         let size = WKInterfaceDevice.current().screenBounds.size
@@ -21,7 +27,7 @@ struct TreatmentMenuView: View {
                 ForEach(treatments) { treatment in
                     Button(action: {
                         selectedTreatment = treatment
-                        dismiss() // Close after selecting
+                        onSelect()
                     }) {
                         HStack(spacing: 10) {
                             switch treatment {

+ 51 - 17
Trio Watch App Extension/Views/TrioMainWatchView.swift

@@ -1,7 +1,22 @@
 import Charts
 import SwiftUI
 
+class NavigationState: ObservableObject {
+    @Published var path = NavigationPath() // Tracks the navigation stack
+
+    func resetToRoot() {
+        path.removeLast(path.count) // Clears the navigation stack to return to root
+    }
+}
+
+enum NavigationDestinations: String {
+    case carbInput
+    case bolusInput
+    case bolusConfirm
+}
+
 struct TrioMainWatchView: View {
+    @StateObject private var navigationState = NavigationState() // Shared navigation state
     @State private var state = WatchState()
 
     // misc
@@ -12,8 +27,7 @@ struct TrioMainWatchView: View {
     // view visbility
     @State private var showingTreatmentMenuSheet: Bool = false
     @State private var showingOverrideSheet: Bool = false
-    @State private var navigateToCarbsInput = false
-    @State private var navigateToBolusInput = false
+    // navigation flag for meal bolus combo
     @State private var continueToBolus = false
 
     // treatments
@@ -26,7 +40,7 @@ struct TrioMainWatchView: View {
     )
 
     var body: some View {
-        NavigationStack {
+        NavigationStack(path: $navigationState.path) {
             TabView(selection: $currentPage) {
                 // Page 1: Current glucose trend in "BG bobble"
                 GlucoseTrendView(state: state, rotationDegrees: rotationDegrees)
@@ -44,6 +58,9 @@ struct TrioMainWatchView: View {
                     updateRotation(for: newTrend)
                 }
             }
+            .onAppear {
+                state.confirmationProgress = 0 // reset auth progress
+            }
             .toolbar {
                 ToolbarItem(placement: .topBarLeading) {
                     HStack {
@@ -91,10 +108,12 @@ struct TrioMainWatchView: View {
                 }
             }
             .sheet(isPresented: $showingTreatmentMenuSheet) {
-                TreatmentMenuView(selectedTreatment: $selectedTreatment)
-                    .onDisappear {
-                        handleTreatmentSelection()
-                    }
+                TreatmentMenuView(selectedTreatment: $selectedTreatment) {
+                    handleTreatmentSelection()
+                }
+                .onAppear {
+                    continueToBolus = false
+                }
             }
             .sheet(isPresented: $showingOverrideSheet) {
                 OverridePresetsView(
@@ -108,11 +127,24 @@ struct TrioMainWatchView: View {
                     state: state
                 )
             }
-            .navigationDestination(isPresented: $navigateToCarbsInput) {
-                CarbsInputView(state: state, continueToBolus: continueToBolus)
-            }
-            .navigationDestination(isPresented: $navigateToBolusInput) {
-                BolusInputView(state: state)
+            .navigationDestination(for: NavigationDestinations.self) { destination in
+                switch destination {
+                case .carbInput:
+                    CarbsInputView(
+                        navigationState: navigationState,
+                        state: state,
+                        continueToBolus: selectedTreatment == .mealBolusCombo
+                    )
+                case .bolusInput:
+                    BolusInputView(navigationState: navigationState, state: state)
+                case .bolusConfirm:
+                    BolusConfirmationView(
+                        navigationState: navigationState,
+                        state: state,
+                        bolusAmount: $state.bolusAmount,
+                        confirmationProgress: $state.confirmationProgress
+                    )
+                }
             }
         }
     }
@@ -165,15 +197,17 @@ struct TrioMainWatchView: View {
     }
 
     private func handleTreatmentSelection() {
+        showingTreatmentMenuSheet = false // Dismiss the sheet
+
         guard let treatment = selectedTreatment else { return }
+
         switch treatment {
-        case .mealBolusCombo:
-            navigateToCarbsInput = true
-            continueToBolus = true
         case .meal:
-            navigateToCarbsInput = true
+            navigationState.path.append(NavigationDestinations.carbInput)
         case .bolus:
-            navigateToBolusInput = true
+            navigationState.path.append(NavigationDestinations.bolusInput)
+        case .mealBolusCombo:
+            navigationState.path.append(NavigationDestinations.carbInput)
         }
     }
 }

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

@@ -26,6 +26,8 @@ import WatchConnectivity
     var carbsAmount: Int = 0
     var fatAmount: Int = 0
     var proteinAmount: Int = 0
+    var bolusAmount = 0.0
+    var confirmationProgress = 0.0
 
     override init() {
         super.init()
@@ -78,6 +80,24 @@ import WatchConnectivity
         }
     }
 
+    /// Sends a meal and bolus insulin combo request to the paired iPhone
+    /// - Parameters:
+    ///   - amount: The insulin amount to be delivered
+    ///   - isExternal: Indicates if the bolus is from an external source
+    func sendMealBolusComboRequest(carbsAmount _: Decimal, bolusAmount: Decimal, _ date: Date = Date()) {
+        guard let session = session, session.isReachable else { return }
+
+        let message: [String: Any] = [
+            "bolus": bolusAmount,
+            "carbs": bolusAmount,
+            "date": date.timeIntervalSince1970
+        ]
+
+        session.sendMessage(message, replyHandler: nil) { error in
+            print("Error sending meal bolus combo request: \(error.localizedDescription)")
+        }
+    }
+
     func sendCancelOverrideRequest() {
         guard let session = session, session.isReachable else { return }
 

+ 11 - 1
Trio/Sources/APS/OpenAPS/Script.swift

@@ -6,7 +6,17 @@ struct Script {
 
     init(name: String) {
         self.name = name
-        body = try! String(contentsOf: Bundle.main.url(forResource: "javascript/\(name)", withExtension: "")!)
+        if let url = Bundle.main.url(forResource: "javascript/\(name)", withExtension: "") {
+            do {
+                body = try String(contentsOf: url)
+            } catch {
+                print("Error loading script: \(error.localizedDescription)")
+                body = "Error loading script"
+            }
+        } else {
+            print("Resource not found: javascript/\(name)")
+            body = "Resource not found"
+        }
     }
 
     init(name: String, body: String) {

+ 5 - 1
Trio/Sources/Logger/Logger.swift

@@ -114,6 +114,7 @@ final class Logger {
     static let nightscout = Logger(category: .nightscout, reporter: baseReporter)
     static let remoteControl = Logger(category: .remoteControl, reporter: baseReporter)
     static let bolusState = Logger(category: .bolusState, reporter: baseReporter)
+    static let watchManager = Logger(category: .watchManager, reporter: baseReporter)
 
     enum Category: String {
         case `default`
@@ -125,6 +126,7 @@ final class Logger {
         case nightscout
         case remoteControl
         case bolusState
+        case watchManager
 
         var name: String {
             rawValue.capitalizingFirstLetter()
@@ -141,6 +143,7 @@ final class Logger {
             case .nightscout: return .nightscout
             case .remoteControl: return .remoteControl
             case .bolusState: return .bolusState
+            case .watchManager: return .watchManager
             }
         }
 
@@ -155,7 +158,8 @@ final class Logger {
                  .nightscout,
                  .openAPS,
                  .remoteControl,
-                 .service:
+                 .service,
+                 .watchManager:
                 return OSLog(subsystem: subsystem, category: name)
             }
         }

+ 89 - 34
Trio/Sources/Services/WatchManager/AppleWatchManager.swift

@@ -101,9 +101,9 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
             session.activate()
             self.session = session
 
-            print("📱 Phone session setup - isPaired: \(session.isPaired)")
+            debug(.watchManager, "📱 Phone session setup - isPaired: \(session.isPaired)")
         } else {
-            print("📱 WCSession is not supported on this device")
+            debug(.watchManager, "📱 WCSession is not supported on this device")
         }
     }
 
@@ -112,7 +112,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
         guard let session = session else { return }
 
         if !session.isReachable {
-            print("📱 Attempting to reactivate session...")
+            debug(.watchManager, "📱 Attempting to reactivate session...")
             session.activate()
         }
     }
@@ -203,7 +203,9 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
             // Set units
             watchState.units = self.units
 
-            print(
+            debug(
+                .watchManager,
+
                 "📱 Setup WatchState - currentGlucose: \(watchState.currentGlucose ?? "nil"), trend: \(watchState.trend ?? "nil"), delta: \(watchState.delta ?? "nil"), values: \(watchState.glucoseValues.count)"
             )
 
@@ -236,7 +238,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
     /// - Parameter state: Current WatchState containing glucose data to be sent
     func sendDataToWatch(_ state: WatchState) {
         guard let session = session, session.isReachable else {
-            print("⌚️ Watch not reachable")
+            debug(.watchManager, "⌚️ Watch not reachable")
             return
         }
 
@@ -267,13 +269,13 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
             }
         ]
 
-        print("📱 Sending to watch - Message content:")
+        debug(.watchManager, "📱 Sending to watch - Message content:")
         message.forEach { key, value in
-            print("📱 \(key): \(value) (type: \(type(of: value)))")
+            debug(.watchManager, "📱 \(key): \(value) (type: \(type(of: value)))")
         }
 
         session.sendMessage(message, replyHandler: nil) { error in
-            print("❌ Error sending data: \(error.localizedDescription)")
+            debug(.watchManager, "❌ Error sending data: \(error.localizedDescription)")
         }
     }
 
@@ -281,12 +283,12 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
 
     func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
         if let error = error {
-            print("📱 Phone session activation failed: \(error.localizedDescription)")
+            debug(.watchManager, "📱 Phone session activation failed: \(error.localizedDescription)")
             return
         }
 
-        print("📱 Phone session activated with state: \(activationState.rawValue)")
-        print("📱 Phone isReachable after activation: \(session.isReachable)")
+        debug(.watchManager, "📱 Phone session activated with state: \(activationState.rawValue)")
+        debug(.watchManager, "📱 Phone isReachable after activation: \(session.isReachable)")
 
         // Try to send initial data after activation
         Task {
@@ -297,36 +299,50 @@ 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
+            if let bolusAmount = message["bolus"] as? Double,
+               message["carbs"] == nil,
+               message["date"] == nil
             {
+                debug(.watchManager, "📱 Received bolus request from watch: \(bolusAmount)U")
                 self?.handleBolusRequest(Decimal(bolusAmount))
-            }
-
-            if let carbsAmount = message["carbs"] as? Int,
-               let timestamp = message["date"] as? TimeInterval
+            } else if let carbsAmount = message["carbs"] as? Int,
+                      let timestamp = message["date"] as? TimeInterval,
+                      message["bolus"] == nil
             {
                 let date = Date(timeIntervalSince1970: timestamp)
-                print("📱 Received carbs request from watch: \(carbsAmount)g at \(date)")
+                debug(.watchManager, "📱 Received carbs request from watch: \(carbsAmount)g at \(date)")
                 self?.handleCarbsRequest(carbsAmount, date)
+            } else if let bolusAmount = message["bolus"] as? Double,
+                      let carbsAmount = message["carbs"] as? Int,
+                      let timestamp = message["date"] as? TimeInterval
+            {
+                let date = Date(timeIntervalSince1970: timestamp)
+                debug(
+                    .watchManager,
+                    "📱 Received meal bolus combo request from watch: \(bolusAmount)U, \(carbsAmount)g at \(date)"
+                )
+                self?.handleCombinedRequest(bolusAmount: Decimal(bolusAmount), carbsAmount: Decimal(carbsAmount), date: date)
+            } else {
+                debug(.watchManager, "📱 Invalid or incomplete data received from watch. Received:  \(message)")
             }
 
             if message["cancelOverride"] as? Bool == true {
-                print("📱 Received cancel override request from watch")
+                debug(.watchManager, "📱 Received cancel override request from watch")
                 self?.handleCancelOverride()
             }
 
             if let presetName = message["activateOverride"] as? String {
-                print("📱 Received activate override request from watch for preset: \(presetName)")
+                debug(.watchManager, "📱 Received activate override request from watch for preset: \(presetName)")
                 self?.handleActivateOverride(presetName)
             }
 
             if let presetName = message["activateTempTarget"] as? String {
-                print("📱 Received activate temp target request from watch for preset: \(presetName)")
+                debug(.watchManager, "📱 Received activate temp target request from watch for preset: \(presetName)")
                 self?.handleActivateTempTarget(presetName)
             }
 
             if message["cancelTempTarget"] as? Bool == true {
-                print("📱 Received cancel temp target request from watch")
+                debug(.watchManager, "📱 Received cancel temp target request from watch")
                 self?.handleCancelTempTarget()
             }
         }
@@ -340,7 +356,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
     #endif
 
     func sessionReachabilityDidChange(_ session: WCSession) {
-        print("📱 Phone reachability changed: \(session.isReachable)")
+        debug(.watchManager, "📱 Phone reachability changed: \(session.isReachable)")
 
         if session.isReachable {
             // Try to send data when connection is established
@@ -361,7 +377,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
     private func handleBolusRequest(_ amount: Decimal) {
         Task {
             await apsManager.enactBolus(amount: Double(amount), isSMB: false)
-            print("📱 Enacted bolus via APS Manager: \(amount)U")
+            debug(.watchManager, "📱 Enacted bolus via APS Manager: \(amount)U")
         }
     }
 
@@ -384,14 +400,47 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                 do {
                     guard context.hasChanges else { return }
                     try context.save()
-                    print("📱 Saved carbs from watch: \(amount)g at \(date)")
+                    debug(.watchManager, "📱 Saved carbs from watch: \(amount)g at \(date)")
                 } catch {
-                    print("❌ Error saving carbs: \(error.localizedDescription)")
+                    debug(.watchManager, "❌ Error saving carbs: \(error.localizedDescription)")
                 }
             }
         }
     }
 
+    /// Handles combined bolus and carbs entry requests received from the Watch.
+    /// - Parameters:
+    ///   - bolusAmount: The bolus amount in units
+    ///   - carbsAmount: The carbs amount in grams
+    ///   - date: Timestamp for the carbs entry
+    private func handleCombinedRequest(bolusAmount: Decimal, carbsAmount: Decimal, date: Date) {
+        Task {
+            let context = CoreDataStack.shared.newTaskContext()
+
+            do {
+                // Save carbs entry in Core Data
+                try await context.perform {
+                    let carbEntry = CarbEntryStored(context: context)
+                    carbEntry.carbs = NSDecimalNumber(decimal: carbsAmount).doubleValue
+                    carbEntry.date = date
+
+                    // TODO: Add Fat-Protein Units (FPU) logic if required
+
+                    guard context.hasChanges else { return }
+                    try context.save()
+                    debug(.watchManager, "📱 Saved carbs from watch: \(carbsAmount)g at \(date)")
+                }
+
+                // Enact bolus via APS Manager
+                let bolusDouble = NSDecimalNumber(decimal: bolusAmount).doubleValue
+                await apsManager.enactBolus(amount: bolusDouble, isSMB: false)
+                debug(.watchManager, "📱 Enacted bolus from watch via APS Manager: \(bolusDouble)U")
+            } catch {
+                debug(.watchManager, "❌ Error processing combined request: \(error.localizedDescription)")
+            }
+        }
+    }
+
     private func handleCancelOverride() {
         Task {
             let context = CoreDataStack.shared.newTaskContext()
@@ -408,7 +457,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                         do {
                             guard context.hasChanges else { return }
                             try context.save()
-                            print("📱 Successfully cancelled override")
+                            debug(.watchManager, "📱 Successfully cancelled override")
 
                             // Send notification to update Adjustments UI
                             Foundation.NotificationCenter.default.post(
@@ -416,7 +465,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                                 object: nil
                             )
                         } catch {
-                            print("❌ Error cancelling override: \(error.localizedDescription)")
+                            debug(.watchManager, "❌ Error cancelling override: \(error.localizedDescription)")
                         }
                     }
                 }
@@ -456,7 +505,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                     do {
                         guard context.hasChanges else { return }
                         try context.save()
-                        print("📱 Successfully activated override: \(presetName)")
+                        debug(.watchManager, "📱 Successfully activated override: \(presetName)")
 
                         // Send notification to update Adjustments UI
                         Foundation.NotificationCenter.default.post(
@@ -464,7 +513,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                             object: nil
                         )
                     } catch {
-                        print("❌ Error activating override: \(error.localizedDescription)")
+                        debug(.watchManager, "❌ Error activating override: \(error.localizedDescription)")
                     }
                 }
             }
@@ -487,7 +536,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                         do {
                             guard context.hasChanges else { return }
                             try context.save()
-                            print("📱 Successfully cancelled temp target")
+                            debug(.watchManager, "📱 Successfully cancelled temp target")
 
                             // To cancel the temp target also for oref
                             self.tempTargetStorage.saveTempTargetsToStorage([TempTarget.cancel(at: Date())])
@@ -498,7 +547,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                                 object: nil
                             )
                         } catch {
-                            print("❌ Error cancelling temp target: \(error.localizedDescription)")
+                            debug(.watchManager, "❌ Error cancelling temp target: \(error.localizedDescription)")
                         }
                     }
                 }
@@ -538,7 +587,12 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                     do {
                         guard context.hasChanges else { return }
                         try context.save()
-                        print("📱 Successfully activated temp target: \(presetName)")
+                        debug(.watchManager, "📱 Successfully activated temp target: \(presetName)")
+
+                        let settingsHalfBasalTarget = self.settingsManager.preferences
+                            .halfBasalExerciseTarget
+
+                        let halfBasalTarget = presetToActivate.halfBasalTarget?.decimalValue
 
                         // To activate the temp target also in oref
                         let tempTarget = TempTarget(
@@ -551,8 +605,9 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                             reason: TempTarget.custom,
                             isPreset: true,
                             enabled: true,
-                            halfBasalTarget: presetToActivate.halfBasalTarget?.decimalValue
+                            halfBasalTarget: halfBasalTarget ?? settingsHalfBasalTarget
                         )
+
                         self.tempTargetStorage.saveTempTargetsToStorage([tempTarget])
 
                         // Send notification to update Adjustments UI
@@ -561,7 +616,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                             object: nil
                         )
                     } catch {
-                        print("❌ Error activating temp target: \(error.localizedDescription)")
+                        debug(.watchManager, "❌ Error activating temp target: \(error.localizedDescription)")
                     }
                 }
             }