|
|
@@ -252,9 +252,11 @@ extension Bolus {
|
|
|
|
|
|
// MARK: - Button tasks
|
|
|
|
|
|
- @MainActor func invokeTreatmentsTask() {
|
|
|
+ func invokeTreatmentsTask() {
|
|
|
Task {
|
|
|
- addButtonPressed = true
|
|
|
+ await MainActor.run {
|
|
|
+ self.addButtonPressed = true
|
|
|
+ }
|
|
|
let isInsulinGiven = amount > 0
|
|
|
let isCarbsPresent = carbs > 0
|
|
|
let isFatPresent = fat > 0
|
|
|
@@ -263,7 +265,9 @@ extension Bolus {
|
|
|
if isInsulinGiven {
|
|
|
try await handleInsulin(isExternal: externalInsulin)
|
|
|
} else if isCarbsPresent || isFatPresent || isProteinPresent {
|
|
|
- waitForSuggestion = true
|
|
|
+ await MainActor.run {
|
|
|
+ self.waitForSuggestion = true
|
|
|
+ }
|
|
|
} else {
|
|
|
hideModal()
|
|
|
return
|
|
|
@@ -280,16 +284,19 @@ extension Bolus {
|
|
|
|
|
|
// MARK: - Insulin
|
|
|
|
|
|
- @MainActor private func handleInsulin(isExternal: Bool) async throws {
|
|
|
+ private func handleInsulin(isExternal: Bool) async throws {
|
|
|
if !isExternal {
|
|
|
await addPumpInsulin()
|
|
|
} else {
|
|
|
await addExternalInsulin()
|
|
|
}
|
|
|
- waitForSuggestion = true
|
|
|
+
|
|
|
+ await MainActor.run {
|
|
|
+ self.waitForSuggestion = true
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- @MainActor func addPumpInsulin() async {
|
|
|
+ func addPumpInsulin() async {
|
|
|
guard amount > 0 else {
|
|
|
showModal(for: nil)
|
|
|
return
|
|
|
@@ -306,7 +313,7 @@ extension Bolus {
|
|
|
}
|
|
|
} catch {
|
|
|
print("authentication error for pump bolus: \(error.localizedDescription)")
|
|
|
- DispatchQueue.main.async {
|
|
|
+ await MainActor.run {
|
|
|
self.waitForSuggestion = false
|
|
|
if self.addButtonPressed {
|
|
|
self.hideModal()
|
|
|
@@ -340,13 +347,15 @@ extension Bolus {
|
|
|
|
|
|
// MARK: - EXTERNAL INSULIN
|
|
|
|
|
|
- @MainActor func addExternalInsulin() async {
|
|
|
+ func addExternalInsulin() async {
|
|
|
guard amount > 0 else {
|
|
|
showModal(for: nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- amount = min(amount, maxBolus * 3)
|
|
|
+ await MainActor.run {
|
|
|
+ self.amount = min(self.amount, self.maxBolus * 3)
|
|
|
+ }
|
|
|
|
|
|
do {
|
|
|
let authenticated = try await unlockmanager.unlock()
|
|
|
@@ -360,7 +369,7 @@ extension Bolus {
|
|
|
}
|
|
|
} catch {
|
|
|
print("authentication error for external insulin: \(error.localizedDescription)")
|
|
|
- DispatchQueue.main.async {
|
|
|
+ await MainActor.run {
|
|
|
self.waitForSuggestion = false
|
|
|
if self.addButtonPressed {
|
|
|
self.hideModal()
|
|
|
@@ -371,10 +380,13 @@ extension Bolus {
|
|
|
|
|
|
// MARK: - Carbs
|
|
|
|
|
|
- @MainActor func saveMeal() async {
|
|
|
+ func saveMeal() async {
|
|
|
guard carbs > 0 || fat > 0 || protein > 0 else { return }
|
|
|
- carbs = min(carbs, maxCarbs)
|
|
|
- id_ = UUID().uuidString
|
|
|
+
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.carbs = min(self.carbs, self.maxCarbs)
|
|
|
+ self.id_ = UUID().uuidString
|
|
|
+ }
|
|
|
|
|
|
let carbsToStore = [CarbsEntry(
|
|
|
id: id_,
|