- 의도(사용자 TestFlight 피드백): 폰으로 운동해도 워치를 차고 있으면 워치가 심박을 재고, 진동은 시작한 기기에서만. 종전 '워치 연동됨' 배지는 워치 앱 포그라운드 여부(isReachable)만 보여 주던 것이라 폐지 - iOS: WatchHeartRateBridge — 시작 시 HKHealthStore.startWatchApp(폰 설정 운동 유형)으로 워치 앱을 깨우고, 워치가 미러링한 HKWorkoutSession을 workoutSessionMirroringStartHandler로 받아 심박 수신, 완주/중단 명령 전송(finish/discard). 워치를 못 열거나 30초 안에 미러링이 안 붙으면 폰 단독 (+설정에 따라 '워치 앱을 열지 못했어요' 알럿, app.watchWarn 재사용) 및 WatchConnectivity로 워치 세션 폐기 명령. 워치 저장 결과(saved/failed)는 WC로 회신받고 15초 내 미회신이면 폰 사후 저장 폴백. 워치 깨우기는 폰 건강 권한 응답 뒤에(첫 실행 경합 방지). 건강 읽기 권한(심박·활성 에너지) 추가 — 워치 세션 센서 수집용(권한 공유) - 워치: WatchAppDelegate.handle(workoutConfiguration) → MirroredWorkoutSession(라이브 빌더, 무진동·무타이머, 심박을 미러링 채널로 전송, finish 시 저장+강도 relate 후 WC로 결과 통보, discard/끊김 시 폐기, 미러링 30초 타임아웃, 앱 재기동 시 잔류 세션 복구·폐기). 화면 '아이폰에서 진행 중 ♥bpm'(중단 버튼). WatchHealthAuth로 권한 공용화 - UI: 첫 화면 배지·확인 창 제거, 운동 화면 횟수 아래 워치 상태 줄(연결 중/♥bpm/아이폰만), 설정 토글 '워치 연결 실패 경고', 도움말 3건 갱신. l10n 카탈로그 3종 missing/stale 0 - DEBUG: -testConfig(35초 세트), -mockWatchHeartRate <bpm>(상태 줄 QA·스크린샷). watchHR 카테고리 notice 로그 - 시뮬 검증(페어링 심): startWatchApp → 워치 기동·권한·세션·가짜 심박·'아이폰에서 진행 중'까지 동작, 워치 startMirroring 성공 반환 — 그러나 폰 미러링 핸들러는 시뮬에서 불리지 않음(애플 샘플도 실기기 전용) → 30초 타임아웃·알럿·WC 폐기·폰 폴백 저장 경로 확인, 워치 자체 세트 정상. 3타깃 빌드 그린·경고 0. 미러링 수신·완주 저장·회신은 실기기 TestFlight 재테스트 필요 - 문서·마케팅: CLAUDE.md §3.8 신설·§1/§3.7/§4/§6/§7 갱신, 설명 3언어·whats-new·review-notes·PRIVACY.md (아이폰 읽기 권한 설명 — GitHub 게시본 갱신 필요), 스크린샷 01·08(배지 제거)·02·03(♥78 상태 줄) 재촬영·합성 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UPmp29DQHY6Ahfss5SRopT
178 lines
6.4 KiB
Swift
178 lines
6.4 KiB
Swift
//
|
|
// ContentView.swift
|
|
// KegingWatch Watch App
|
|
//
|
|
// 실행하면 바로 시작 버튼 하나 — 누르면 즉시 시작.
|
|
// 왼쪽으로 스와이프하면 워치 전용 세팅 페이지(7차 — 세팅은 아이폰과 독립).
|
|
// 진행 중엔 수축/이완·남은 시간·몇 번째인지 한 화면에.
|
|
// 아이폰이 깨운 심박 세션 중(MirroredWorkoutSession)에는 시작 버튼 대신 '아이폰에서 진행 중' 화면(§3.8).
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct WatchContentView: View {
|
|
@EnvironmentObject private var engine: KegelEngine
|
|
@EnvironmentObject private var settings: SettingsStore
|
|
@ObservedObject private var mirror = MirroredWorkoutSession.shared
|
|
@Environment(\.scenePhase) private var scenePhase
|
|
@State private var page = 0
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
AppTheme.background.ignoresSafeArea()
|
|
switch engine.state {
|
|
case .idle:
|
|
if mirror.isActive {
|
|
mirroredScreen
|
|
} else {
|
|
TabView(selection: $page) {
|
|
startScreen.tag(0)
|
|
WatchSettingsView().tag(1)
|
|
}
|
|
.tabViewStyle(.page)
|
|
}
|
|
case let .running(phase, rep, phaseStart, phaseEnd):
|
|
runningScreen(phase: phase, rep: rep, phaseStart: phaseStart, phaseEnd: phaseEnd)
|
|
case let .finished(reps):
|
|
finishedScreen(reps: reps)
|
|
}
|
|
}
|
|
.onChange(of: scenePhase) { _, newPhase in
|
|
guard newPhase == .active else { return }
|
|
// 손목을 올려 앱이 다시 보일 때 — 벽시계 기준 국면 재정렬
|
|
engine.resyncAfterWake()
|
|
}
|
|
.onAppear {
|
|
#if DEBUG
|
|
if CommandLine.arguments.contains("-openSettings") { page = 1 }
|
|
if CommandLine.arguments.contains("-autoStart") { WatchCoordinator.shared.startWorkout() }
|
|
#endif
|
|
}
|
|
}
|
|
|
|
private var startScreen: some View {
|
|
VStack(spacing: 8) {
|
|
Button {
|
|
WatchCoordinator.shared.startWorkout()
|
|
} label: {
|
|
ZStack {
|
|
Circle()
|
|
.fill(
|
|
LinearGradient(
|
|
colors: [AppTheme.green, AppTheme.green.opacity(0.8)],
|
|
startPoint: .top, endPoint: .bottom
|
|
)
|
|
)
|
|
VStack(spacing: 2) {
|
|
Image(systemName: "play.fill").font(.title3)
|
|
Text("시작").font(.headline)
|
|
}
|
|
.foregroundStyle(Color(hex: "#0F2018"))
|
|
}
|
|
.frame(width: 108, height: 108)
|
|
}
|
|
.buttonStyle(.plain)
|
|
.accessibilityLabel(Text("케겔 운동 시작"))
|
|
|
|
// 세팅 페이지에서 바꾸면 즉시 반영되는 요약 한 줄
|
|
Text(settings.config.summaryText)
|
|
.font(.system(size: 11))
|
|
.foregroundStyle(.secondary)
|
|
.lineLimit(1)
|
|
.minimumScaleFactor(0.7)
|
|
}
|
|
}
|
|
|
|
/// 아이폰에서 시작한 세트 — 워치는 심박만 잰다 (타이머·진동은 아이폰)
|
|
private var mirroredScreen: some View {
|
|
VStack(spacing: 5) {
|
|
Image(systemName: "iphone.radiowaves.left.and.right")
|
|
.font(.title3)
|
|
.foregroundStyle(AppTheme.green)
|
|
Text("아이폰에서 진행 중")
|
|
.font(.headline)
|
|
HStack(spacing: 4) {
|
|
Image(systemName: "heart.fill")
|
|
.foregroundStyle(.red)
|
|
if let bpm = mirror.heartRate {
|
|
Text(verbatim: "\(Int(bpm.rounded()))")
|
|
.font(.system(size: 28, weight: .semibold))
|
|
.monospacedDigit()
|
|
} else {
|
|
Text("심박 측정 중")
|
|
.font(.footnote)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
.accessibilityElement(children: .combine)
|
|
Text("진동은 아이폰에서 울려요")
|
|
.font(.caption2)
|
|
.foregroundStyle(.secondary)
|
|
Button {
|
|
MirroredWorkoutSession.shared.cancelByUser()
|
|
} label: {
|
|
Text("중단")
|
|
.font(.footnote)
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.tint(.red)
|
|
.padding(.top, 2)
|
|
}
|
|
}
|
|
|
|
private func runningScreen(phase: KegelPhase, rep: Int, phaseStart: Date, phaseEnd: Date) -> some View {
|
|
VStack(spacing: 3) {
|
|
Text(phase.label)
|
|
.font(.title3.bold())
|
|
.foregroundStyle(phaseColor(phase))
|
|
Text(timerInterval: phaseStart...phaseEnd, countsDown: true)
|
|
.font(.system(size: 30, weight: .semibold))
|
|
.monospacedDigit()
|
|
.multilineTextAlignment(.center)
|
|
Text("\(rep) / \(engine.config.reps)")
|
|
.font(.footnote)
|
|
.monospacedDigit()
|
|
.foregroundStyle(.secondary)
|
|
.accessibilityLabel(Text("현재 \(rep)번째, 전체 \(engine.config.reps)회"))
|
|
Button {
|
|
WatchCoordinator.shared.stopWorkout()
|
|
} label: {
|
|
Text("중단")
|
|
.font(.footnote)
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.tint(.red)
|
|
.padding(.top, 2)
|
|
}
|
|
}
|
|
|
|
private func phaseColor(_ phase: KegelPhase) -> Color {
|
|
switch phase {
|
|
case .prepare: .gray
|
|
case .contract: AppTheme.green
|
|
case .relax: AppTheme.yellow
|
|
}
|
|
}
|
|
|
|
private func finishedScreen(reps: Int) -> some View {
|
|
VStack(spacing: 6) {
|
|
Image(systemName: "checkmark.circle.fill")
|
|
.font(.system(size: 34))
|
|
.foregroundStyle(AppTheme.green)
|
|
Text("완료!")
|
|
.font(.headline)
|
|
Text("\(reps)회 완주")
|
|
.font(.footnote)
|
|
.foregroundStyle(.secondary)
|
|
Button {
|
|
engine.acknowledgeFinish()
|
|
} label: {
|
|
Text("확인")
|
|
.font(.footnote)
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.padding(.top, 2)
|
|
}
|
|
}
|
|
}
|