Park the Watch run while iPhone edits an exercise or split

Publish an exclusive-edit lock (editingWorkoutID / editingSplitID) in the
phone→watch application context. While the phone has a workout's exercise
(ExerciseView) or a split (SplitDetailView) open in an editor, the watch pops
out of that run, blocks re-entry, and shows it as "Editing on iPhone" — so the
two devices never drive the same run at once and the watch can't clobber the
phone's edit with a stale optimistic write. The lock clears when the editor
closes; absent keys in the latest-wins context mean "not editing".

Claude-Session: https://claude.ai/code/session_01SCv7zvGFcKy47KSTnTLxRe
This commit is contained in:
2026-06-20 19:54:31 -04:00
parent 50838832d4
commit 8ef0e96b31
7 changed files with 129 additions and 12 deletions
@@ -14,6 +14,7 @@ import UIKit
struct ExerciseView: View {
@Environment(SyncEngine.self) private var sync
@Environment(AppServices.self) private var services
@Environment(\.dismiss) private var dismiss
let workout: Workout
@@ -69,9 +70,12 @@ struct ExerciseView: View {
progress = log?.currentStateIndex ?? 0
// Keep the screen lit while logging sets a mid-workout sleep is annoying.
UIApplication.shared.isIdleTimerDisabled = true
// Take over this run: the watch parks and locks it while we're editing here.
services.watchBridge.setEditingWorkout(workout.id)
}
.onDisappear {
UIApplication.shared.isIdleTimerDisabled = false
services.watchBridge.setEditingWorkout(nil)
}
// 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