Просмотр исходного кода

Remove insulinReq guardrail, fix threading

- Thanks to @marvout for the assist
- Make bolus shortcuts thread safe
- Also stripped out the insulinReq guard rail option after consensus in 10 person group discussion that we don't want this
Auggie Fisher 1 год назад
Родитель
Сommit
1afd9db494

+ 10 - 10
FreeAPS.xcodeproj/project.pbxproj

@@ -496,7 +496,7 @@
 /* Begin PBXCopyFilesBuildPhase section */
 		3821ECD025DC703C00BC42AD /* Embed Frameworks */ = {
 			isa = PBXCopyFilesBuildPhase;
-			buildActionMask = 2147483647;
+			buildActionMask = 8;
 			dstPath = "";
 			dstSubfolderSpec = 10;
 			files = (
@@ -509,18 +509,18 @@
 				CE95BF5E2BA770C300DC3DE3 /* LoopKitUI.framework in Embed Frameworks */,
 			);
 			name = "Embed Frameworks";
-			runOnlyForDeploymentPostprocessing = 0;
+			runOnlyForDeploymentPostprocessing = 1;
 		};
 		38E8753D27554D5900975559 /* Embed Watch Content */ = {
 			isa = PBXCopyFilesBuildPhase;
-			buildActionMask = 2147483647;
+			buildActionMask = 8;
 			dstPath = "$(CONTENTS_FOLDER_PATH)/Watch";
 			dstSubfolderSpec = 16;
 			files = (
 				38E8753C27554D5900975559 /* FreeAPSWatch.app in Embed Watch Content */,
 			);
 			name = "Embed Watch Content";
-			runOnlyForDeploymentPostprocessing = 0;
+			runOnlyForDeploymentPostprocessing = 1;
 		};
 		38E8754027554D5900975559 /* Embed App Extensions */ = {
 			isa = PBXCopyFilesBuildPhase;
@@ -535,14 +535,14 @@
 		};
 		6B1A8D122B14D88E00E76752 /* Embed Foundation Extensions */ = {
 			isa = PBXCopyFilesBuildPhase;
-			buildActionMask = 2147483647;
+			buildActionMask = 8;
 			dstPath = "";
 			dstSubfolderSpec = 13;
 			files = (
 				6B1A8D282B14D91700E76752 /* LiveActivityExtension.appex in Embed Foundation Extensions */,
 			);
 			name = "Embed Foundation Extensions";
-			runOnlyForDeploymentPostprocessing = 0;
+			runOnlyForDeploymentPostprocessing = 1;
 		};
 /* End PBXCopyFilesBuildPhase section */
 
@@ -2819,7 +2819,7 @@
 		CE95BF582BA5F8F300DC3DE3 /* Install plugins */ = {
 			isa = PBXShellScriptBuildPhase;
 			alwaysOutOfDate = 1;
-			buildActionMask = 2147483647;
+			buildActionMask = 8;
 			files = (
 			);
 			inputFileListPaths = (
@@ -2831,13 +2831,13 @@
 			);
 			outputPaths = (
 			);
-			runOnlyForDeploymentPostprocessing = 0;
+			runOnlyForDeploymentPostprocessing = 1;
 			shellPath = /bin/sh;
 			shellScript = "\"${SRCROOT}/Scripts/copy-plugins.sh\"\n";
 		};
 		DD88C8DF2C4D583900F2D558 /* ShellScript */ = {
 			isa = PBXShellScriptBuildPhase;
-			buildActionMask = 2147483647;
+			buildActionMask = 8;
 			files = (
 			);
 			inputFileListPaths = (
@@ -2848,7 +2848,7 @@
 			);
 			outputPaths = (
 			);
-			runOnlyForDeploymentPostprocessing = 0;
+			runOnlyForDeploymentPostprocessing = 1;
 			shellPath = /bin/sh;
 			shellScript = "\"${SRCROOT}/scripts/capture-build-details.sh\"\n";
 		};

+ 0 - 3
FreeAPS/Sources/Models/FreeAPSSettings.swift

@@ -4,7 +4,6 @@ enum BolusShortcutLimit: String, JSON, CaseIterable, Identifiable {
     var id: String { rawValue }
     case notAllowed
     case limitBolusMax
-    case limitInsulinSuggestion
 
     var displayName: String {
         switch self {
@@ -12,8 +11,6 @@ enum BolusShortcutLimit: String, JSON, CaseIterable, Identifiable {
             return String(localized: "Not allowed", table: "ShortcutsDetail")
         case .limitBolusMax:
             return String(localized: "Max bolus", table: "ShortcutsDetail")
-        case .limitInsulinSuggestion:
-            return String(localized: "Insulin recommended", table: "ShortcutsDetail")
         }
     }
 }

+ 0 - 11
FreeAPS/Sources/Modules/ShortcutsConfig/View/ShortcutsConfigView.swift

@@ -25,17 +25,6 @@ extension ShortcutsConfig {
                         String(localized: "Allow bolusing with shortcuts", table: "ShortcutsDetail"),
                         isOn: $state.allowBolusByShortcuts
                     )
-
-                    Picker(
-                        selection: $state.maxBolusByShortcuts,
-                        label: Text("Limit bolus from shortcuts to", tableName: "ShortcutsDetail")
-                    ) {
-                        ForEach(BolusShortcutLimit.allCases) { v in
-                            v != .notAllowed ? Text(v.displayName).tag(v) : nil
-                            // Text(v.displayName).tag(v)
-                        }
-                    }
-                    .disabled(!state.allowBolusByShortcuts)
                 }
             }
             .onAppear(perform: configureView)

+ 1 - 0
FreeAPS/Sources/Shortcuts/BaseIntentsRequest.swift

@@ -17,6 +17,7 @@ import Swinject
     let resolver: Resolver
 
     let coredataContext = CoreDataStack.shared.newTaskContext()
+    let viewContext = CoreDataStack.shared.persistentContainer.viewContext
 
     override init() {
         resolver = FreeAPSApp.resolver

+ 5 - 60
FreeAPS/Sources/Shortcuts/Bolus/BolusIntentRequest.swift

@@ -3,12 +3,6 @@ import CoreData
 import Foundation
 
 @available(iOS 16.0,*) final class BolusIntentRequest: BaseIntentsRequest {
-    private var suggestion: Determination? {
-        // TODO: CRITICAL
-        /// This MUST update to use the latest determination's insulinRequired from Core Data
-        fileStorage.retrieve(OpenAPS.Enact.suggested, as: Determination.self)
-    }
-
     func bolus(_ bolusAmount: Double) async throws -> LocalizedStringResource {
         var bolusQuantity: Decimal = 0
         switch settingsManager.settings.bolusShortcut {
@@ -30,60 +24,11 @@ import Foundation
                 bolusQuantity = apsManager.roundBolus(amount: Decimal(bolusAmount))
             }
 
-        // Block any bolus attempted if it is larger than the insulin recommended
-        case .limitInsulinSuggestion:
-            /*
-             case .limitInsulinSuggestion:
-                 let lastDetermination = await CoreDataStack.shared.fetchEntitiesAsync(
-                     ofType: OrefDetermination.self,
-                     onContext: coredataContext,
-                     predicate: NSPredicate.predicateFor30MinAgoForDetermination,
-                     key: "deliveryAt", ascending: false,
-                     fetchLimit: 1
-                 )
-                 guard let latest = lastDetermination.first else {
-                     return LocalizedStringResource(
-                         "Error retrieving suggested insulin amount guardrail.",
-                         table: "ShortcutsDetail"
-                     )
-                 }
-                 let insulinSuggestion = latest.insulinForManualBolus ?? 0
-             */
-            let insulinSuggestion = suggestion?.insulinForManualBolus ?? 0
-            if Decimal(bolusAmount) > insulinSuggestion {
-                return LocalizedStringResource(
-                    "The bolus cannot be larger than the suggested insulin (\(insulinSuggestion.description)).",
-                    table: "ShortcutsDetail"
-                )
-            }
-            // Also make sure that no matter what, the bolus doesn't exceed the max setting in Trio
-            else if Decimal(bolusAmount) > settingsManager.pumpSettings.maxBolus {
-                return LocalizedStringResource(
-                    "The bolus cannot be larger than the pump setting max bolus (\(settingsManager.pumpSettings.maxBolus.description)).",
-                    table: "ShortcutsDetail"
-                )
-            } else {
-                bolusQuantity = apsManager
-                    .roundBolus(amount: Decimal(bolusAmount))
-            }
-        }
-
-        await apsManager.enactBolus(amount: Double(bolusQuantity), isSMB: false)
-        return LocalizedStringResource(
-            "A bolus command of \(bolusQuantity.formatted()) U of insulin was sent",
-            table: "ShortcutsDetail"
-        )
-    }
-
-    private var glucoseFormatter: NumberFormatter {
-        let formatter = NumberFormatter()
-        formatter.numberStyle = .decimal
-        formatter.maximumFractionDigits = 0
-        if settingsManager.settings.units == .mmolL {
-            formatter.minimumFractionDigits = 1
-            formatter.maximumFractionDigits = 1
+            await apsManager.enactBolus(amount: Double(bolusQuantity), isSMB: false)
+            return LocalizedStringResource(
+                "A bolus command of \(bolusQuantity.formatted()) U of insulin was sent",
+                table: "ShortcutsDetail"
+            )
         }
-        formatter.roundingMode = .halfUp
-        return formatter
     }
 }

+ 1 - 1
Trio.xcworkspace/xcshareddata/swiftpm/Package.resolved

@@ -49,7 +49,7 @@
     {
       "identity" : "swiftcharts",
       "kind" : "remoteSourceControl",
-      "location" : "https://github.com/ivanschuetz/SwiftCharts",
+      "location" : "https://github.com/ivanschuetz/SwiftCharts.git",
       "state" : {
         "branch" : "master",
         "revision" : "c354c1945bb35a1f01b665b22474f6db28cba4a2"