Rework the Apple Watch progress flow

Watch root lists every in-progress workout; picking an exercise runs a paged Ready -> work/rest -> Finish flow (One More + auto-firing Done), with a phase-dot row and brand-tinted count-up/down timers. Includes the configurable rest and auto-finish settings synced over WatchConnectivity and the wrist-down timer fix.
This commit is contained in:
2026-06-20 14:15:31 -04:00
parent f2da47a70a
commit f06c4e996e
9 changed files with 373 additions and 111 deletions
@@ -8,37 +8,57 @@
import SwiftUI
import SwiftData
/// Root of the watch app. The watch only runs the workout that's currently active
/// on the phone there's no history browsing here. The "active" workout is the most
/// recent cached one that isn't finished (`notStarted` or `inProgress`); a workout is
/// Root of the watch app. The watch only runs the workouts that are currently
/// active on the phone there's no history browsing here. An "active" workout is a
/// cached one that isn't finished (`notStarted` or `inProgress`); a workout is
/// created on the phone as `notStarted` the moment a split is picked, and flips to
/// `completed` once every exercise is done, at which point we fall back to the gate.
/// `completed` once every exercise is done, at which point it drops off this list.
///
/// The root shows every active workout (most-recent first); picking one opens its
/// exercise list.
struct ActiveWorkoutGateView: View {
@Environment(WatchConnectivityBridge.self) private var bridge
@Environment(WorkoutSessionManager.self) private var sessionManager
@Query(sort: \Workout.start, order: .reverse) private var workouts: [Workout]
@Query private var splits: [Split]
private var activeWorkout: Workout? {
workouts.first { $0.status == .inProgress || $0.status == .notStarted }
private var activeWorkouts: [Workout] {
workouts.filter { $0.status == .inProgress || $0.status == .notStarted }
}
private func split(for workout: Workout) -> Split? {
guard let id = workout.splitID else { return nil }
return splits.first { $0.id == id }
}
var body: some View {
NavigationStack {
if let workout = activeWorkout {
WorkoutLogListView(workout: workout)
} else {
emptyState
Group {
if activeWorkouts.isEmpty {
emptyState
} else {
List {
ForEach(activeWorkouts) { workout in
NavigationLink {
WorkoutLogListView(workout: workout)
} label: {
ActiveWorkoutRow(workout: workout, split: split(for: workout))
}
}
}
.navigationTitle("In Progress")
}
}
}
.task {
// Nothing to run yet pull fresh state in case the phone just started one.
if activeWorkout == nil { bridge.requestSync() }
if activeWorkouts.isEmpty { bridge.requestSync() }
}
.onChange(of: activeWorkout == nil) { _, noActiveWorkout in
// The workout finished (or was cleared) release the HealthKit session that
.onChange(of: activeWorkouts.isEmpty) { _, noActiveWorkouts in
// Everything finished (or was cleared) release the HealthKit session that
// was keeping the launched app alive.
if noActiveWorkout { sessionManager.end() }
if noActiveWorkouts { sessionManager.end() }
}
}
@@ -56,3 +76,38 @@ struct ActiveWorkoutGateView: View {
}
}
}
// MARK: - Active Workout Row
private struct ActiveWorkoutRow: View {
let workout: Workout
let split: Split?
private var logs: [WorkoutLog] { workout.logsArray }
private var doneCount: Int { logs.filter { $0.status == .completed }.count }
var body: some View {
HStack(spacing: 10) {
Image(systemName: split?.systemImage ?? "figure.strengthtraining.traditional")
.font(.title3)
.foregroundStyle(split.map { Color.color(from: $0.color) } ?? .workTint)
.frame(width: 26)
VStack(alignment: .leading, spacing: 2) {
Text(workout.splitName ?? Split.unnamed)
.font(.headline)
.lineLimit(1)
Text(subtitle)
.font(.caption2)
.foregroundStyle(.secondary)
}
}
}
private var subtitle: String {
guard !logs.isEmpty else { return workout.start.formattedDate() }
if doneCount == 0 { return "Not started · \(logs.count) exercises" }
return "\(doneCount) of \(logs.count) done"
}
}