Mirror a live Apple Watch run on a propped-up iPhone
Add an ephemeral live-run presence channel (separate from the durable iCloud progress sync) so a propped-up iPhone can mirror the Watch's Ready → work/rest → Finish flow in real time as the user swipes. Watch drives, phone mirrors (read-only), so there's no echo loop: - Watch's ExerciseProgressView broadcasts a LiveProgress frame on every phase transition (and an ended signal on leave) via sendMessage, reachable-only — throwaway presence, never written to iCloud. - Timers ride as wall-clock anchors (Date kept native in the WC dict to preserve sub-second precision), so both devices count independently off shared start times and stay in lockstep without streaming ticks. - Phone holds a transient LiveRunState; ContentView auto-presents a read-only LiveProgressMirrorView full-screen cover while a run is live. Claude-Session: https://claude.ai/code/session_01SCv7zvGFcKy47KSTnTLxRe
This commit is contained in:
@@ -12,6 +12,7 @@ import WatchConnectivity
|
||||
final class PhoneConnectivityBridge: NSObject {
|
||||
private let container: ModelContainer
|
||||
private let syncEngine: SyncEngine
|
||||
private let liveRunState: LiveRunState
|
||||
private var session: WCSession?
|
||||
|
||||
/// Exclusive-edit lock published to the watch. While the phone has a workout's
|
||||
@@ -24,9 +25,10 @@ final class PhoneConnectivityBridge: NSObject {
|
||||
|
||||
private var context: ModelContext { container.mainContext }
|
||||
|
||||
init(container: ModelContainer, syncEngine: SyncEngine) {
|
||||
init(container: ModelContainer, syncEngine: SyncEngine, liveRunState: LiveRunState) {
|
||||
self.container = container
|
||||
self.syncEngine = syncEngine
|
||||
self.liveRunState = liveRunState
|
||||
super.init()
|
||||
}
|
||||
|
||||
@@ -90,6 +92,14 @@ final class PhoneConnectivityBridge: NSObject {
|
||||
if let doc = WCPayload.decodeWorkoutUpdate(dict) {
|
||||
Task { @MainActor in await self.syncEngine.ingestFromWatch(doc) }
|
||||
}
|
||||
case WCPayload.liveProgressType:
|
||||
if let frame = WCPayload.decodeLiveProgress(dict) {
|
||||
Task { @MainActor in self.liveRunState.apply(frame) }
|
||||
}
|
||||
case WCPayload.liveEndedType:
|
||||
if let logID = dict[WCPayload.lpLogIDKey] as? String {
|
||||
Task { @MainActor in self.liveRunState.end(logID: logID) }
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user