polscm32 aka Marvout 1 год назад
Родитель
Сommit
f1bba85987

+ 30 - 34
FreeAPS/Sources/Modules/BasalProfileEditor/BasalProfileEditorStateModel.swift

@@ -107,16 +107,14 @@ extension BasalProfileEditor {
                 .store(in: &lifetime)
                 .store(in: &lifetime)
         }
         }
 
 
-        func validate() {
-            DispatchQueue.main.async {
-                let uniq = Array(Set(self.items))
-                let sorted = uniq.sorted { $0.timeIndex < $1.timeIndex }
-                sorted.first?.timeIndex = 0
-                if self.items != sorted {
-                    self.items = sorted
-                }
-                self.calcTotal()
+        @MainActor func validate() {
+            let uniq = Array(Set(items))
+            let sorted = uniq.sorted { $0.timeIndex < $1.timeIndex }
+            sorted.first?.timeIndex = 0
+            if items != sorted {
+                items = sorted
             }
             }
+            calcTotal()
         }
         }
 
 
         func availableTimeIndices(_ itemIndex: Int) -> [Int] {
         func availableTimeIndices(_ itemIndex: Int) -> [Int] {
@@ -133,32 +131,30 @@ extension BasalProfileEditor {
             return (0 ..< timeValues.count).filter { !usedIndicesByOtherItems.contains($0) }
             return (0 ..< timeValues.count).filter { !usedIndicesByOtherItems.contains($0) }
         }
         }
 
 
-        func caluclateChartData() {
-            DispatchQueue.main.async {
-                var basals: [BasalProfile] = []
-                let tzOffset = TimeZone.current.secondsFromGMT() * -1
-
-                basals.append(contentsOf: self.items.enumerated().map { index, item in
-                    let startDate = Date(timeIntervalSinceReferenceDate: self.timeValues[item.timeIndex])
-                    var endDate = Date(timeIntervalSinceReferenceDate: self.timeValues.last!).addingTimeInterval(30 * 60)
-                    if self.items.count > index + 1 {
-                        let nextItem = self.items[index + 1]
-                        endDate = Date(timeIntervalSinceReferenceDate: self.timeValues[nextItem.timeIndex])
-                    }
+        @MainActor func calculateChartData() {
+            var basals: [BasalProfile] = []
+            let tzOffset = TimeZone.current.secondsFromGMT() * -1
 
 
-                    return BasalProfile(
-                        amount: Double(self.rateValues[item.rateIndex]),
-                        isOverwritten: false,
-                        startDate: startDate.addingTimeInterval(TimeInterval(tzOffset)),
-                        endDate: endDate.addingTimeInterval(TimeInterval(tzOffset))
-                    )
-                })
-                basals.sort(by: {
-                    $0.startDate > $1.startDate
-                })
-
-                self.chartData = basals
-            }
+            basals.append(contentsOf: items.enumerated().map { index, item in
+                let startDate = Date(timeIntervalSinceReferenceDate: self.timeValues[item.timeIndex])
+                var endDate = Date(timeIntervalSinceReferenceDate: self.timeValues.last!).addingTimeInterval(30 * 60)
+                if self.items.count > index + 1 {
+                    let nextItem = self.items[index + 1]
+                    endDate = Date(timeIntervalSinceReferenceDate: self.timeValues[nextItem.timeIndex])
+                }
+
+                return BasalProfile(
+                    amount: Double(self.rateValues[item.rateIndex]),
+                    isOverwritten: false,
+                    startDate: startDate.addingTimeInterval(TimeInterval(tzOffset)),
+                    endDate: endDate.addingTimeInterval(TimeInterval(tzOffset))
+                )
+            })
+            basals.sort(by: {
+                $0.startDate > $1.startDate
+            })
+
+            chartData = basals
         }
         }
     }
     }
 }
 }

+ 3 - 4
FreeAPS/Sources/Modules/BasalProfileEditor/View/BasalProfileEditorRootView.swift

@@ -154,7 +154,7 @@ extension BasalProfileEditor {
             }
             }
             .onChange(of: state.items) {
             .onChange(of: state.items) {
                 state.calcTotal()
                 state.calcTotal()
-                state.caluclateChartData()
+                state.calculateChartData()
             }
             }
             .scrollContentBackground(.hidden).background(color)
             .scrollContentBackground(.hidden).background(color)
             .navigationTitle("Basal Profile")
             .navigationTitle("Basal Profile")
@@ -171,7 +171,7 @@ extension BasalProfileEditor {
             .onAppear {
             .onAppear {
                 configureView()
                 configureView()
                 state.validate()
                 state.validate()
-                state.caluclateChartData()
+                state.calculateChartData()
             }
             }
         }
         }
 
 
@@ -254,8 +254,7 @@ extension BasalProfileEditor {
         private func onDelete(offsets: IndexSet) {
         private func onDelete(offsets: IndexSet) {
             state.items.remove(atOffsets: offsets)
             state.items.remove(atOffsets: offsets)
             state.validate()
             state.validate()
-            state.calcTotal()
-            state.caluclateChartData()
+            state.calculateChartData()
         }
         }
     }
     }
 }
 }

+ 1 - 1
FreeAPS/Sources/Modules/RemoteControl/TrioRemoteControl+APNS.swift

@@ -28,6 +28,6 @@ extension TrioRemoteControl {
     }
     }
 
 
     private func isRunningInAPNSProductionEnvironment() -> Bool {
     private func isRunningInAPNSProductionEnvironment() -> Bool {
-        return BuildDetails.default.isTestFlightBuild()
+        BuildDetails.default.isTestFlightBuild()
     }
     }
 }
 }