Explorar el Código

Read simulator lifecycle/highlight in home timer tick

Without a real CGMManager the timer was setting cgmDisplayState to nil every 5s. Read from the simulator source as a fallback so the same code path serves both.
trioneer hace 2 semanas
padre
commit
cfc83eb33a
Se han modificado 1 ficheros con 19 adiciones y 4 borrados
  1. 19 4
      Trio/Sources/Modules/Home/HomeStateModel.swift

+ 19 - 4
Trio/Sources/Modules/Home/HomeStateModel.swift

@@ -332,11 +332,26 @@ extension Home {
                     self.timerDate = Date()
                     // The publisher only re-emits on state changes; re-pull
                     // so the arc + countdowns + status text advance during
-                    // warmup / stabilizing / expiry.
+                    // warmup / stabilizing / expiry. Simulator has no
+                    // CGMManager, so fall back to reading its synthetic
+                    // lifecycle / highlight so the bobble sees the same
+                    // data shape a real CGM would deliver.
                     let manager = self.fetchGlucoseManager.cgmManager
-                    let progress = manager?.cgmLifecycleProgress
+                    let source = self.fetchGlucoseManager.glucoseSource
+                    let progress: DeviceLifecycleProgress?
+                    let highlight: DeviceStatusHighlight?
+                    if let manager {
+                        progress = manager.cgmLifecycleProgress
+                        highlight = manager.cgmStatusHighlight
+                    } else if let sim = source as? GlucoseSimulatorSource {
+                        progress = sim.cgmLifecycleProgress
+                        highlight = sim.cgmStatusHighlight
+                    } else {
+                        progress = nil
+                        highlight = nil
+                    }
                     self.cgmProgressHighlight = progress
-                    if let highlight = manager?.cgmStatusHighlight {
+                    if let highlight {
                         self.cgmDisplayState = CgmDisplayState(
                             localizedMessage: highlight.localizedMessage,
                             imageName: highlight.imageName,
@@ -347,7 +362,7 @@ extension Home {
                     }
                     self.cgmSensorExpiresAt = Self.resolveSensorExpiresAt(
                         manager: manager,
-                        glucoseSource: self.fetchGlucoseManager.glucoseSource,
+                        glucoseSource: source,
                         lifecycle: progress
                     )
                     self.cgmWarmupEndsAt = Self.resolveWarmupEndsAt(manager: manager)