Add HIIT watch runner, rest-time setting, and HealthKit watch auto-launch
- Redesign the watch app into an active-workout runner: a root gate shows the in-progress workout's exercises or prompts to start one on iPhone, and each exercise runs as a horizontally-paged HIIT cycle (count-up work, count-down rest with final-three-second haptics + auto-advance, One More / Done on the last set). Replaces the old history list. - Add a configurable rest-between-sets duration in iPhone Settings (default 45s), synced to the watch over WatchConnectivity. - Launch the watch app into the session when a workout starts on the phone via HealthKit (startWatchApp); the watch runs an HKWorkoutSession for foreground runtime and ends it when the workout finishes. Adds the HealthKit entitlement + Health usage strings on both targets and WKBackgroundModes on the watch. Claude-Session: https://claude.ai/code/session_018gg69MaUetDNzWzBXisfMV
This commit is contained in:
@@ -32,6 +32,7 @@ final class WatchConnectivityBridge: NSObject {
|
||||
// Apply whatever the phone last pushed, then ask for a fresh push.
|
||||
applyState(WCPayload.decodeSplits(session.receivedApplicationContext),
|
||||
workouts: WCPayload.decodeWorkouts(session.receivedApplicationContext))
|
||||
applyRestSeconds(session.receivedApplicationContext)
|
||||
requestSync()
|
||||
}
|
||||
|
||||
@@ -62,6 +63,12 @@ final class WatchConnectivityBridge: NSObject {
|
||||
}
|
||||
}
|
||||
|
||||
private func applyRestSeconds(_ dict: [String: Any]) {
|
||||
if let rest = WCPayload.decodeRestSeconds(dict) {
|
||||
UserDefaults.standard.set(rest, forKey: WCPayload.restSecondsKey)
|
||||
}
|
||||
}
|
||||
|
||||
private func applyState(_ splits: [SplitDocument], workouts: [WorkoutDocument]) {
|
||||
guard !splits.isEmpty || !workouts.isEmpty else { return }
|
||||
var liveSplitIDs = Set<String>()
|
||||
@@ -93,6 +100,10 @@ extension WatchConnectivityBridge: WCSessionDelegate {
|
||||
nonisolated func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String: Any]) {
|
||||
let splits = WCPayload.decodeSplits(applicationContext)
|
||||
let workouts = WCPayload.decodeWorkouts(applicationContext)
|
||||
Task { @MainActor in self.applyState(splits, workouts: workouts) }
|
||||
let rest = WCPayload.decodeRestSeconds(applicationContext)
|
||||
Task { @MainActor in
|
||||
self.applyState(splits, workouts: workouts)
|
||||
if let rest { UserDefaults.standard.set(rest, forKey: WCPayload.restSecondsKey) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user