Files
workouts/Workouts Watch App/Views/WatchSettingsView.swift
T
rzen 373f812968 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.
2026-07-16 20:18:47 -04:00

40 lines
1.4 KiB
Swift

//
// 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)
}
}
}