Refresh the exercise detail screen live on external workout changes

ExerciseView now observes workout.updatedAt and pulls the latest doc/progress
from the cache, mirroring WorkoutLogListView. A set completed on the watch now
advances the iPhone set grid in real time instead of only on re-entry.

Claude-Session: https://claude.ai/code/session_018gg69MaUetDNzWzBXisfMV
This commit is contained in:
2026-06-19 17:58:38 -04:00
parent 180f07e23c
commit 1d856b98d0
2 changed files with 16 additions and 1 deletions
+2 -1
View File
@@ -19,7 +19,8 @@ All notable changes to this project are documented here.
- Fixed: progress made on the watch now updates open iPhone screens live. The - Fixed: progress made on the watch now updates open iPhone screens live. The
phone applies a watch-forwarded workout to its cache directly on receipt, instead phone applies a watch-forwarded workout to its cache directly on receipt, instead
of waiting on an `NSMetadataQuery` event that a same-process file overwrite of waiting on an `NSMetadataQuery` event that a same-process file overwrite
doesn't reliably emit. doesn't reliably emit — and the exercise detail screen now observes these updates,
so its set grid advances in real time without leaving and re-entering the screen.
- Starting a workout on the iPhone now launches the Apple Watch app straight into - Starting a workout on the iPhone now launches the Apple Watch app straight into
the session via HealthKit (a one-time Health permission); the watch holds an the session via HealthKit (a one-time Health permission); the watch holds an
`HKWorkoutSession` to stay active while you train and releases it when the `HKWorkoutSession` to stay active while you train and releases it when the
@@ -63,6 +63,20 @@ struct ExerciseView: View {
refreshDocIfNeeded() refreshDocIfNeeded()
progress = log?.currentStateIndex ?? 0 progress = log?.currentStateIndex ?? 0
} }
// Reflect external changes (e.g. a set completed on the watch) live. Each edit
// rewrites the whole workout file, so the cache always holds the latest pulling
// it in can't revert a newer local tap.
.onChange(of: workout.updatedAt) { _, _ in
absorbExternalUpdate()
}
}
/// Pull an externally-changed workout into the working copy so the set grid and plan
/// update without leaving and re-entering the screen.
private func absorbExternalUpdate() {
let fresh = WorkoutDocument(from: workout)
doc = fresh
progress = fresh.logs.first(where: { $0.id == logID })?.currentStateIndex ?? progress
} }
@ViewBuilder @ViewBuilder