Add a live status panel between the run screen's halves

Replaces the small target-HR pill on the iPhone run screen with a
glanceable big-digit strip between the timer flow and the figure —
heart rate (band-tinted with the cue arrow when the run carries a
target), HR zone, active calories, and the workout stopwatch. A
horizontal band in portrait, a vertical column in landscape (the
inverse of the half-and-half split, so it always sits between them).

The watch now rides the running calorie total and the HR zone (1-5,
computed watch-side where max HR is known) along with each live HR
sample; absent keys keep older builds wire-compatible both ways.
LiveRunState holds all three under the shared staleness expiry. The
screenshot rig seeds believable values so the run capture shows the
panel populated.
This commit is contained in:
2026-07-16 18:54:39 -04:00
parent a0f14f46e1
commit aa23d7baa7
10 changed files with 167 additions and 57 deletions
+18 -6
View File
@@ -38,10 +38,19 @@ final class WorkoutSessionManager: NSObject {
private(set) var currentHeartRate: Double?
private(set) var currentActiveEnergyKcal: Double?
/// One live reading for the phone's status panel: the fresh heart rate plus the
/// session's running calorie total and the HR zone (15) that rate falls in.
/// `kcal`/`zone` are nil while unknown (no energy sample yet / max HR unknown).
struct LiveSample {
let bpm: Double
let kcal: Double?
let zone: Int?
}
/// Fired with each fresh heart-rate sample while the session runs. The bridge hangs
/// off this to forward the reading to the phone (best-effort, display-only) a
/// callback rather than observation so the sensor stream has exactly one push path.
var onHeartRateSample: ((Double) -> Void)?
var onHeartRateSample: ((LiveSample) -> Void)?
/// Seconds accumulated in each of 5 heart-rate zones (lowhigh). Built on the
/// watch because it's the only place with the full HR stream. Empty/ignored when
@@ -187,14 +196,17 @@ final class WorkoutSessionManager: NSObject {
let dt = now.timeIntervalSince(last)
if dt > 0, dt < 60 { hrZoneSeconds[Self.zoneIndex(for: prevHR, maxHR: maxHeartRate)] += dt }
}
if let newHR {
currentHeartRate = newHR
onHeartRateSample?(newHR)
}
lastHRSampleDate = now
// Refresh the calorie total before forwarding, so the sample carries it.
currentActiveEnergyKcal = builder?.statistics(for: HKQuantityType(.activeEnergyBurned))?
.sumQuantity()?.doubleValue(for: .kilocalorie())
if let newHR {
currentHeartRate = newHR
let zone = maxHeartRate.map { Self.zoneIndex(for: newHR, maxHR: $0) + 1 }
onHeartRateSample?(LiveSample(bpm: newHR, kcal: currentActiveEnergyKcal, zone: zone))
}
lastHRSampleDate = now
}
/// Bucket an instantaneous heart rate into one of five zones (04) by its fraction of the