Adjust rest time from the watch with the same 1-second stepper
A gear on the watch root opens a small Settings sheet whose stepper edits the shared restSeconds default (10-180s, 1s steps). Edits ride a new settingsUpdate message to the phone - debounced per stepper burst, falling back to transferUserInfo when unreachable - which clamps the value, writes the shared default, and re-echoes it to every device through the application context. While an edit is pending on the watch, an in-flight context's stale rest value is skipped so it can't yank the stepper back mid-edit.
This commit is contained in:
@@ -27,6 +27,8 @@ struct ActiveWorkoutGateView: View {
|
||||
/// takes over editing the run we're inside.
|
||||
@State private var path: [ActiveWorkoutRoute] = []
|
||||
|
||||
@State private var showingSettings = false
|
||||
|
||||
private var activeWorkouts: [Workout] {
|
||||
workouts.filter { $0.status == .inProgress || $0.status == .notStarted }
|
||||
}
|
||||
@@ -66,6 +68,19 @@ struct ActiveWorkoutGateView: View {
|
||||
WorkoutLogListView(workout: workout)
|
||||
}
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
Button {
|
||||
showingSettings = true
|
||||
} label: {
|
||||
Image(systemName: "gearshape")
|
||||
}
|
||||
.accessibilityLabel("Settings")
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showingSettings) {
|
||||
NavigationStack { WatchSettingsView() }
|
||||
}
|
||||
// The phone's pushes aren't decoding (its app updated first; this one hasn't
|
||||
// yet) — everything shown is frozen at the last good sync. Say so rather than
|
||||
// silently presenting stale workouts until the watch app catches up.
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// WatchSettingsView.swift
|
||||
// Workouts Watch App
|
||||
//
|
||||
// Copyright 2026 Rouslan Zenetl. All Rights Reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
/// The watch's small settings sheet — just the rest time today, adjusted with the
|
||||
/// same 1-second stepper as the iPhone. The value lives in the shared defaults key
|
||||
/// the phone pushes; edits are forwarded back so the phone (the durable owner)
|
||||
/// re-echoes them to every device.
|
||||
struct WatchSettingsView: View {
|
||||
@Environment(WatchConnectivityBridge.self) private var bridge
|
||||
|
||||
/// Shared with the phone via the same defaults key (see `WCPayload.restSecondsKey`).
|
||||
@AppStorage("restSeconds") private var restSeconds: Int = 45
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section {
|
||||
Stepper(value: $restSeconds, in: 10...180, step: 1) {
|
||||
Text("\(restSeconds)s")
|
||||
.font(.system(.title3, design: .rounded, weight: .semibold))
|
||||
.monospacedDigit()
|
||||
}
|
||||
} header: {
|
||||
Text("Rest Between Sets")
|
||||
} footer: {
|
||||
Text("Used between sets and, when auto-advancing, between exercises. A routine's custom rest time overrides it.")
|
||||
}
|
||||
}
|
||||
.navigationTitle("Settings")
|
||||
.onChange(of: restSeconds) { _, seconds in
|
||||
bridge.sendRestSeconds(seconds)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user