End the watch session on Discard, plus start-flow UX tweaks
Watch-side follow-through for the End Workout flow: - The phone now pushes an authoritative set (in-progress, not-started, and completed within 24h) instead of the 25 most-recent workouts, and the watch prunes any workout absent from it. So a Discard/Delete (or a completed run aging out) drops off the watch, empties its active list, and ends the HKWorkoutSession — fixing the persistent wrist-raise re-foregrounding. The watch never originates a workout, so pruning can't lose local data; the 24h grace keeps a just-finished run on screen. The gate pops if the run you're viewing is pruned. UX tweaks: - The in-workout ⋯ is now a pull-down Menu (Add Exercise / End Workout) rather than an action sheet. - Starting a split while another workout is still active now prompts to end the current one(s) — keeping their progress — or run in parallel. Wired into both start paths (the split picker and "Start This Split"), via a shared WorkoutDocument.endKeepingProgress() helper. Claude-Session: https://claude.ai/code/session_01SCv7zvGFcKy47KSTnTLxRe
This commit is contained in:
@@ -185,15 +185,22 @@ final class WatchConnectivityBridge: NSObject {
|
||||
CacheMapper.upsertSplit(s, relativePath: s.relativePath, into: context)
|
||||
liveSplitIDs.insert(s.id)
|
||||
}
|
||||
var liveWorkoutIDs = Set<String>()
|
||||
for w in workouts {
|
||||
CacheMapper.upsertWorkout(w, relativePath: w.relativePath, into: context)
|
||||
liveWorkoutIDs.insert(w.id)
|
||||
}
|
||||
// Splits are sent in full → prune any the phone no longer has. Workouts are
|
||||
// sent as a recent window, so they're upserted but never pruned (avoids a
|
||||
// race deleting a workout just created on the watch).
|
||||
// Both are authoritative sets → prune anything the phone no longer sends. For
|
||||
// workouts that set is every active run plus recently-completed ones (~24h), so a
|
||||
// run that was discarded/deleted on the phone (or aged out of the window) drops out
|
||||
// of the push and is pruned here — which empties the active list and ends the
|
||||
// session. The watch never originates a workout, so pruning can't lose local data.
|
||||
if let allSplits = try? context.fetch(FetchDescriptor<Split>()) {
|
||||
for s in allSplits where !liveSplitIDs.contains(s.id) { context.delete(s) }
|
||||
}
|
||||
if let allWorkouts = try? context.fetch(FetchDescriptor<Workout>()) {
|
||||
for w in allWorkouts where !liveWorkoutIDs.contains(w.id) { context.delete(w) }
|
||||
}
|
||||
try? context.save()
|
||||
lastSyncDate = Date()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user