- 'cannot find in scope' 판정: 새 DerivedData 클린룸 빌드 3종(Debug/Release/워치) 전부 그린 → SourceKit 편집기 오탐 확정 (실제 컴파일 에러 0) - 강제 종료 유령 Live Activity 정리: 운동 중 kill 시 DI가 몇 시간 잔존(시뮬 재현) → 앱 시작 시 cleanupStaleActivities()로 즉시 소멸(실측 확인) - 진동 체인 세대 토큰: 짧은 수축·이완에서 이전 패턴 체인이 다음 국면 첫 진동을 삼키는 엣지 방지, Haptics를 Task 기반으로 재작성해 Swift 6 경고 3건 전부 제거 - 워치에도 -noHealth QA 인자 추가 - 시뮬 실측: DI 백그라운드 갱신(수축 그린→이완 앰버)·포그라운드 복귀 벽시계 재동기화 (5/20 정확 착지)·유령 DI 정리·주간 통계 검산(11세트/220회)·완주 경로·워치 실행· 18.5 빌드 그린·전 카탈로그 missing/stale/ASCII~ 0 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UPmp29DQHY6Ahfss5SRopT
58 lines
1.8 KiB
Swift
58 lines
1.8 KiB
Swift
//
|
|
// WorkoutCoordinator.swift
|
|
// Keging
|
|
//
|
|
// 엔진 ↔ 진동·Live Activity·백그라운드 오디오·화면 꺼짐 방지 배선 (iOS)
|
|
//
|
|
|
|
import UIKit
|
|
|
|
@MainActor
|
|
final class WorkoutCoordinator {
|
|
static let shared = WorkoutCoordinator()
|
|
|
|
private var wired = false
|
|
|
|
private init() {}
|
|
|
|
func wire() {
|
|
guard !wired else { return }
|
|
wired = true
|
|
|
|
LiveActivityManager.shared.cleanupStaleActivities()
|
|
|
|
let engine = KegelEngine.shared
|
|
engine.onPhaseChange = { [weak engine] phase, rep, phaseEnd in
|
|
guard let engine else { return }
|
|
let config = engine.config
|
|
switch phase {
|
|
case .prepare: break // 준비는 무진동 — 첫 수축 진동이 시작 신호
|
|
case .contract: Haptics.play(config.contractPattern)
|
|
case .relax: Haptics.play(config.relaxPattern)
|
|
}
|
|
LiveActivityManager.shared.sync(phase: phase, rep: rep, totalReps: config.reps, phaseEnd: phaseEnd)
|
|
}
|
|
engine.onSessionEnd = { completed, record in
|
|
LiveActivityManager.shared.end()
|
|
BackgroundAudioKeeper.shared.stop()
|
|
UIApplication.shared.isIdleTimerDisabled = false
|
|
if completed, let record {
|
|
let config = SettingsStore.shared.config
|
|
HealthRecorder.shared.save(
|
|
record: record,
|
|
effortScore: config.effortScore,
|
|
workoutType: config.healthWorkoutType
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
func startWorkout() {
|
|
guard !KegelEngine.shared.isRunning else { return }
|
|
HealthRecorder.shared.requestAuthorizationIfNeeded()
|
|
BackgroundAudioKeeper.shared.start()
|
|
UIApplication.shared.isIdleTimerDisabled = true
|
|
KegelEngine.shared.start(config: SettingsStore.shared.config)
|
|
}
|
|
}
|