فهرست منبع

Merge branch 'beta-fixes-3' of github.com:nightscout/Trio-dev into beta-watch-fixes

Deniz Cengiz 1 سال پیش
والد
کامیت
70b7976e6c

+ 2 - 0
Trio/Sources/Modules/DataTable/DataTableStateModel.swift

@@ -313,6 +313,8 @@ extension DataTable {
                 )
                 )
 
 
                 await syncWithServices()
                 await syncWithServices()
+                // Perform a determine basal sync to update cob
+                await apsManager.determineBasalSync()
             }
             }
         }
         }
 
 

+ 1 - 1
Trio/Sources/Modules/DataTable/View/CarbEntryEditorView.swift

@@ -171,7 +171,7 @@ struct CarbEntryEditorView: View {
                         selection: $editedDate,
                         selection: $editedDate,
                         displayedComponents: [.date, .hourAndMinute]
                         displayedComponents: [.date, .hourAndMinute]
                     )
                     )
-                }
+                }.listRowBackground(Color.chart)
             }
             }
             .safeAreaInset(
             .safeAreaInset(
                 edge: .bottom,
                 edge: .bottom,

+ 2 - 2
Trio/Sources/Modules/Home/HomeStateModel+Setup/DeterminationSetup.swift

@@ -41,9 +41,9 @@ extension Home.StateModel {
             key: "deliverAt",
             key: "deliverAt",
             ascending: false,
             ascending: false,
             batchSize: 50,
             batchSize: 50,
-            propertiesToFetch: ["cob", "iob", "objectID"]
+            propertiesToFetch: ["cob", "iob", "deliverAt", "objectID"]
         )
         )
-
+        
         return await determinationFetchContext.perform {
         return await determinationFetchContext.perform {
             guard let fetchedResults = results as? [[String: Any]] else {
             guard let fetchedResults = results as? [[String: Any]] else {
                 return []
                 return []

+ 18 - 1
Trio/Sources/Modules/Home/View/Chart/ChartElements/CobIobChart.swift

@@ -80,7 +80,24 @@ extension MainChartView {
     }
     }
 
 
     func drawCOBIOBChart() -> some ChartContent {
     func drawCOBIOBChart() -> some ChartContent {
-        ForEach(state.enactedAndNonEnactedDeterminations) { item in
+        // Filter out duplicate entries by `deliverAt`,
+        // We sometimes get two determinations when editing carbs, one without the entry-to-be-edited and then another one after editing the entry.
+        // We are fetching determinations in descending order, so the first one is the latter determination (with correct amounts), so keeping the first one encountered.
+        var seenDates = Set<Date>()
+        let filteredDeterminations = state.enactedAndNonEnactedDeterminations.filter { item in
+            if let date = item.deliverAt {
+                if seenDates.contains(date) {
+                    // Already seen this date – filter it out.
+                    return false
+                } else {
+                    seenDates.insert(date)
+                    return true
+                }
+            }
+            return true
+        }
+
+        return ForEach(filteredDeterminations) { item in
 
 
             // MARK: - COB line and area mark
             // MARK: - COB line and area mark
 
 

+ 3 - 13
Trio/Sources/Services/WatchManager/AppleWatchManager.swift

@@ -45,9 +45,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
     init(resolver: Resolver) {
     init(resolver: Resolver) {
         super.init()
         super.init()
         injectServices(resolver)
         injectServices(resolver)
-        guard setupWatchSession() else {
-            return
-        }
+        setupWatchSession()
 
 
         units = settingsManager.settings.units
         units = settingsManager.settings.units
         glucoseColorScheme = settingsManager.settings.glucoseColorScheme
         glucoseColorScheme = settingsManager.settings.glucoseColorScheme
@@ -125,24 +123,16 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
     }
     }
 
 
     /// Sets up the WatchConnectivity session if the device supports it
     /// Sets up the WatchConnectivity session if the device supports it
-    private func setupWatchSession() -> Bool {
+    private func setupWatchSession() {
         if WCSession.isSupported() {
         if WCSession.isSupported() {
             let session = WCSession.default
             let session = WCSession.default
             session.delegate = self
             session.delegate = self
             session.activate()
             session.activate()
             self.session = session
             self.session = session
-            debug(.watchManager, "📱 Phone session setup - isPaired: \(session.isPaired)")
 
 
-            guard session.isPaired else {
-                debug(.watchManager, "⌚️❌ No Watch is paired")
-                // return here to end any further initialization of Apple Watch Manager
-                return false
-            }
-            return true
+            debug(.watchManager, "📱 Phone session setup - isPaired: \(session.isPaired)")
         } else {
         } else {
             debug(.watchManager, "📱 WCSession is not supported on this device")
             debug(.watchManager, "📱 WCSession is not supported on this device")
-            // return here to end any further initialization of Apple Watch Manager
-            return false
         }
         }
     }
     }