|
|
@@ -36,6 +36,8 @@ final class LiveActivityData: ObservableObject {
|
|
|
@Published var glucoseFromPersistence: [GlucoseData]?
|
|
|
/// The current override data (if any).
|
|
|
@Published var override: OverrideData?
|
|
|
+ /// The current temp target data (if any).
|
|
|
+ @Published var tempTarget: TempTargetData?
|
|
|
/// The widget items displayed within the live activity.
|
|
|
@Published var widgetItems: [LiveActivityAttributes.LiveActivityItem]?
|
|
|
}
|
|
|
@@ -141,6 +143,10 @@ final class LiveActivityData: ObservableObject {
|
|
|
Task { await self?.loadOverrides() }
|
|
|
}.store(in: &subscriptions)
|
|
|
|
|
|
+ coreDataPublisher?.filteredByEntityName("TempTargetStored").sink { [weak self] _ in
|
|
|
+ Task { await self?.loadTempTarget() }
|
|
|
+ }.store(in: &subscriptions)
|
|
|
+
|
|
|
coreDataPublisher?.filteredByEntityName("GlucoseStored").sink { [weak self] _ in
|
|
|
Task { await self?.loadGlucose() }
|
|
|
}.store(in: &subscriptions)
|
|
|
@@ -179,6 +185,15 @@ final class LiveActivityData: ObservableObject {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// Fetches and maps temp target data and updates the live activity content state.
|
|
|
+ private func loadTempTarget() async {
|
|
|
+ do {
|
|
|
+ data.tempTarget = try await fetchAndMapTempTarget()
|
|
|
+ } catch {
|
|
|
+ debug(.default, "[LiveActivityManager] \(DebuggingIdentifiers.failed) failed to fetch and map temp target: \(error)")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// Handles changes to the live activity order.
|
|
|
///
|
|
|
/// Loads widget items from user defaults and triggers an update to the live activity order.
|
|
|
@@ -203,6 +218,7 @@ final class LiveActivityData: ObservableObject {
|
|
|
Task {
|
|
|
await self.loadGlucose()
|
|
|
await self.loadOverrides()
|
|
|
+ await self.loadTempTarget()
|
|
|
await self.loadDetermination()
|
|
|
self.loadWidgetItems()
|
|
|
}
|
|
|
@@ -301,6 +317,11 @@ final class LiveActivityData: ObservableObject {
|
|
|
overrideDate: Date.now,
|
|
|
overrideDuration: 0,
|
|
|
overrideTarget: 0,
|
|
|
+ isTempTargetActive: false,
|
|
|
+ tempTargetName: "",
|
|
|
+ tempTargetDate: Date.now,
|
|
|
+ tempTargetDuration: 0,
|
|
|
+ tempTargetTarget: 0,
|
|
|
widgetItems: []
|
|
|
),
|
|
|
isInitialState: true
|
|
|
@@ -399,6 +420,7 @@ final class LiveActivityData: ObservableObject {
|
|
|
determination: determination,
|
|
|
iob: data.iob,
|
|
|
override: data.override,
|
|
|
+ tempTarget: data.tempTarget,
|
|
|
widgetItems: data.widgetItems
|
|
|
)
|
|
|
|