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

Show descriptive error message when no Passcode configured and unlock operation fails nightscout/Trio#510

Deniz Cengiz 1 год назад
Родитель
Сommit
b012a981f8

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

@@ -37824,6 +37824,9 @@
         }
         }
       }
       }
     },
     },
+    "Authentication failed. Please ensure you have configured a Passcode for your iPhone under iOS Settings > Face ID & Code." : {
+
+    },
     "Authorize Trio to send notifications and use Bluetooth. You must allow both for Trio to work properly." : {
     "Authorize Trio to send notifications and use Bluetooth. You must allow both for Trio to work properly." : {
       "localizations" : {
       "localizations" : {
         "bg" : {
         "bg" : {
@@ -72213,6 +72216,7 @@
       }
       }
     },
     },
     "Determination Failed" : {
     "Determination Failed" : {
+      "extractionState" : "stale",
       "localizations" : {
       "localizations" : {
         "bg" : {
         "bg" : {
           "stringUnit" : {
           "stringUnit" : {
@@ -87923,6 +87927,9 @@
         }
         }
       }
       }
     },
     },
+    "Error while processing Treatment" : {
+
+    },
     "Error! Bolus cancellation failed with error: %@" : {
     "Error! Bolus cancellation failed with error: %@" : {
       "comment" : "Error message for canceling a bolus",
       "comment" : "Error message for canceling a bolus",
       "localizations" : {
       "localizations" : {
@@ -91783,6 +91790,7 @@
       }
       }
     },
     },
     "Failed to update COB/IOB: %@" : {
     "Failed to update COB/IOB: %@" : {
+      "extractionState" : "stale",
       "localizations" : {
       "localizations" : {
         "bg" : {
         "bg" : {
           "stringUnit" : {
           "stringUnit" : {

+ 17 - 6
Trio/Sources/Modules/Treatments/TreatmentsStateModel.swift

@@ -1,6 +1,7 @@
 import Combine
 import Combine
 import CoreData
 import CoreData
 import Foundation
 import Foundation
+import LocalAuthentication
 import LoopKit
 import LoopKit
 import Observation
 import Observation
 import SwiftUI
 import SwiftUI
@@ -474,14 +475,19 @@ extension Treatments {
                     }
                     }
                     await apsManager.enactBolus(amount: maxAmount, isSMB: false, callback: nil)
                     await apsManager.enactBolus(amount: maxAmount, isSMB: false, callback: nil)
                 } else {
                 } else {
-                    print("authentication failed")
+                    debug(.bolusState, "Authentication failed")
+                    throw UnlockError(error: LAError(.authenticationFailed))
                 }
                 }
             } catch {
             } catch {
-                print("authentication error for pump bolus: \(error.localizedDescription)")
+                debug(.bolusState, "Authentication error for pump bolus: \(error)")
                 await MainActor.run {
                 await MainActor.run {
                     self.isAwaitingDeterminationResult = false
                     self.isAwaitingDeterminationResult = false
                     self.showDeterminationFailureAlert = true
                     self.showDeterminationFailureAlert = true
-                    self.determinationFailureMessage = error.localizedDescription
+                    self
+                        .determinationFailureMessage =
+                        String(
+                            localized: "Authentication failed. Please ensure you have configured a Passcode for your iPhone under iOS Settings > Face ID & Code."
+                        )
                 }
                 }
             }
             }
         }
         }
@@ -510,14 +516,19 @@ extension Treatments {
                     // perform determine basal sync
                     // perform determine basal sync
                     try await apsManager.determineBasalSync()
                     try await apsManager.determineBasalSync()
                 } else {
                 } else {
-                    print("authentication failed")
+                    debug(.bolusState, "Authentication failed")
+                    throw UnlockError(error: LAError(.authenticationFailed))
                 }
                 }
             } catch {
             } catch {
-                print("authentication error for external insulin: \(error.localizedDescription)")
+                debug(.bolusState, "authentication error for external insulin: \(error)")
                 await MainActor.run {
                 await MainActor.run {
                     self.isAwaitingDeterminationResult = false
                     self.isAwaitingDeterminationResult = false
                     self.showDeterminationFailureAlert = true
                     self.showDeterminationFailureAlert = true
-                    self.determinationFailureMessage = error.localizedDescription
+                    self
+                        .determinationFailureMessage =
+                        String(
+                            localized: "Authentication failed. Please ensure you have configured a Passcode for your iPhone under iOS Settings > Face ID & Code."
+                        )
                 }
                 }
             }
             }
         }
         }

+ 2 - 2
Trio/Sources/Modules/Treatments/View/TreatmentsRootView.swift

@@ -400,12 +400,12 @@ extension Treatments {
             }) {
             }) {
                 MealPresetView(state: state)
                 MealPresetView(state: state)
             }
             }
-            .alert("Determination Failed", isPresented: $state.showDeterminationFailureAlert) {
+            .alert("Error while processing Treatment", isPresented: $state.showDeterminationFailureAlert) {
                 Button("OK", role: .cancel) {
                 Button("OK", role: .cancel) {
                     state.hideModal()
                     state.hideModal()
                 }
                 }
             } message: {
             } message: {
-                Text("Failed to update COB/IOB: \(state.determinationFailureMessage)")
+                Text("\(state.determinationFailureMessage)")
             }
             }
         }
         }