- CHHapticEngine을 공유 AVAudioSession에 부착(기본 생성 시 독자 오디오 정책이 백그라운드 무음 루프를 끊던 것이 DI 멈춤 원인) + 오디오 키퍼 하드닝(루트 변경· 미디어 서버 리셋·ensureAlive) + 운동 중 2초 하트비트(오디오·엔진·LA 자가 치유) - Live Activity: 실제 phaseStart 사용·동일 상태 no-op·staleDate 8초·isStale 흐림 - 워치 세팅 동기화 3중화: 변경 push + reachability 재푸시 + 워치 앱 열릴 때 sendMessage pull - 완주 진동 신설: 폰 2.4초 연속(백그라운드 6방 체인, 오디오 정지 4초 지연), 워치 retry×2+success - 통계 하루 탭 맨 위 '오늘의 타임라인'(24시간 축 점 그래프, 시각 라벨·지금 룰) - 폰 칼로리 공식을 애플워치 '기타' 운동 규칙(빠르게 걷기 상당)에 정합: MET 4.0+강도×0.15 - 도움말 4건 갱신·en/ja 번역·CFBundleName 보충, CLAUDE.md 현행화 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UPmp29DQHY6Ahfss5SRopT
128 lines
4.3 KiB
Swift
128 lines
4.3 KiB
Swift
//
|
|
// ContentView.swift
|
|
// KegingWatch Watch App
|
|
//
|
|
// 실행하면 바로 시작 버튼 하나 — 누르면 즉시 시작.
|
|
// 진행 중엔 수축/이완·남은 시간·몇 번째인지 한 화면에.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct WatchContentView: View {
|
|
@EnvironmentObject private var engine: KegelEngine
|
|
@Environment(\.scenePhase) private var scenePhase
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
AppTheme.background.ignoresSafeArea()
|
|
switch engine.state {
|
|
case .idle:
|
|
startScreen
|
|
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()
|
|
WatchSync.shared.requestConfigFromPhone()
|
|
}
|
|
.onAppear {
|
|
WatchSync.shared.requestConfigFromPhone()
|
|
#if DEBUG
|
|
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(SettingsStore.shared.config.summaryText)
|
|
.font(.system(size: 11))
|
|
.foregroundStyle(.secondary)
|
|
.lineLimit(1)
|
|
.minimumScaleFactor(0.7)
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|