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

Merge branch 'dev' of github.com:nightscout/Trio-dev into fix-nsfilepermission

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

+ 1 - 0
Trio/Sources/APS/DeviceDataManager.swift

@@ -520,6 +520,7 @@ extension BaseDeviceDataManager: PumpManagerDelegate {
                     guard let type = $0.type, type == .tempBasal else { return true }
                     return $0.dose?.unitsPerHour ?? 0 <= Double(settingsManager.pumpSettings.maxBasal)
                 }
+                debug(.deviceManager, "Storing \(events.count) new pump events: \(events)")
                 try await pumpHistoryStorage.storePumpEvents(events)
                 lastEventDate = events.last?.date
                 completion(nil)

+ 12 - 13
Trio/Sources/APS/Storage/PumpHistoryStorage.swift

@@ -69,7 +69,7 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
 
                     guard existingEvents.isEmpty else {
                         // Duplicate found, do not store the event
-                        print("Duplicate event found with timestamp: \(event.date)")
+                        debug(.coreData, "Duplicate event found with timestamp: \(event.date)")
 
                         if let existingEvent = existingEvents.first(where: { $0.type == EventType.bolus.rawValue }) {
                             if existingEvent.timestamp == event.date {
@@ -81,7 +81,7 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                                     existingEvent.isUploadedToHealth = false
                                     existingEvent.isUploadedToTidepool = false
 
-                                    print("Updated existing event with smaller value: \(amount)")
+                                    debug(.coreData, "Updated existing event with smaller value: \(amount)")
                                 }
                             }
                         }
@@ -108,7 +108,7 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
 
                     guard existingEvents.isEmpty else {
                         // Duplicate found, do not store the event
-                        print("Duplicate event found with timestamp: \(event.date)")
+                        debug(.coreData, "Duplicate event found with timestamp: \(event.date)")
                         continue
                     }
 
@@ -137,7 +137,7 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                 case .suspend:
                     guard existingEvents.isEmpty else {
                         // Duplicate found, do not store the event
-                        print("Duplicate event found with timestamp: \(event.date)")
+                        debug(.coreData, "Duplicate event found with timestamp: \(event.date)")
                         continue
                     }
                     let newPumpEvent = PumpEventStored(context: self.context)
@@ -151,7 +151,7 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                 case .resume:
                     guard existingEvents.isEmpty else {
                         // Duplicate found, do not store the event
-                        print("Duplicate event found with timestamp: \(event.date)")
+                        debug(.coreData, "Duplicate event found with timestamp: \(event.date)")
                         continue
                     }
                     let newPumpEvent = PumpEventStored(context: self.context)
@@ -165,7 +165,7 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                 case .rewind:
                     guard existingEvents.isEmpty else {
                         // Duplicate found, do not store the event
-                        print("Duplicate event found with timestamp: \(event.date)")
+                        debug(.coreData, "Duplicate event found with timestamp: \(event.date)")
                         continue
                     }
                     let newPumpEvent = PumpEventStored(context: self.context)
@@ -179,7 +179,7 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                 case .prime:
                     guard existingEvents.isEmpty else {
                         // Duplicate found, do not store the event
-                        print("Duplicate event found with timestamp: \(event.date)")
+                        debug(.coreData, "Duplicate event found with timestamp: \(event.date)")
                         continue
                     }
                     let newPumpEvent = PumpEventStored(context: self.context)
@@ -193,7 +193,7 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                 case .alarm:
                     guard existingEvents.isEmpty else {
                         // Duplicate found, do not store the event
-                        print("Duplicate event found with timestamp: \(event.date)")
+                        debug(.coreData, "Duplicate event found with timestamp: \(event.date)")
                         continue
                     }
                     let newPumpEvent = PumpEventStored(context: self.context)
@@ -215,16 +215,15 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                 try self.context.save()
 
                 self.updateSubject.send(())
-                debugPrint("\(DebuggingIdentifiers.succeeded) stored pump events in Core Data")
+                debug(.coreData, "\(DebuggingIdentifiers.succeeded) stored pump events in Core Data")
             } catch let error as NSError {
-                debugPrint("\(DebuggingIdentifiers.failed) failed to store pump events with error: \(error.userInfo)")
+                debug(.coreData, "\(DebuggingIdentifiers.failed) failed to store pump events with error: \(error.userInfo)")
                 throw error
             }
         }
     }
 
     func storeExternalInsulinEvent(amount: Decimal, timestamp: Date) async {
-        debug(.default, "External insulin saved")
         await context.perform {
             // create pump event
             let newPumpEvent = PumpEventStored(context: self.context)
@@ -246,10 +245,10 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
             do {
                 guard self.context.hasChanges else { return }
                 try self.context.save()
-
+                debug(.coreData, "External insulin saved")
                 self.updateSubject.send(())
             } catch {
-                print(error.localizedDescription)
+                debug(.coreData, "Failed to store external insulin in context: \(error)")
             }
         }
     }

+ 7 - 2
Trio/Sources/Services/LiveActivity/LiveActivityManager.swift

@@ -305,7 +305,10 @@ final class LiveActivityManager: Injectable, ObservableObject, SettingsObserver
         if let currentActivity = currentActivity {
             if currentActivity.needsRecreation(), UIApplication.shared.applicationState == .active {
                 await endActivity()
-                await pushUpdate(state)
+                Task { @MainActor in
+                    await self.pushUpdate(state)
+                }
+                return
             } else {
                 let content = ActivityContent(
                     state: state,
@@ -408,7 +411,9 @@ final class LiveActivityManager: Injectable, ObservableObject, SettingsObserver
             try? await Task.sleep(nanoseconds: 200_000_000) // 0.2s sleep
         }
 
-        await pushUpdate(contentState)
+        Task { @MainActor in
+            await self.pushUpdate(contentState)
+        }
         debug(.default, "Restarted Live Activity from LiveActivityIntent (via iOS Shortcut)")
     }
 }