mycode/myApp/Keging/Shared/WorkoutSettings.swift
songyc macbook 4d91c48844 feat(keging): 워치 연결 배지·미연결 시작 경고 + 세팅 기기별 독립(워치 좌스와이프 세팅) + 워치 진동 강화 (7차)
- 폰 첫 화면: 시작 버튼 위 워치 연결 배지(연결됨/미연결/미연동 — iOS 제약상
  '연결됨'은 워치 앱 포그라운드 기준, 설정·도움말에 안내), 미연결 시작 시 확인 창
  (기록은 동일함을 안내), 설정 > 애플워치 > '워치 미연결 경고' 토글.
  단축어·autoStart는 경고 없이 통과
- 세팅 동기화 전면 제거(기기마다 진동 질감이 달라 각자 최적화) — 동기화는 기록만.
  워치 시작 화면 왼쪽 스와이프로 전용 세팅 페이지(TabView .page): 준비/수축/이완/
  횟수 스테퍼(2줄 컴팩트 라벨), 진동 2종 피커(선택 즉시 미리 울림), 운동 유형·강도.
  요약 라인 즉시 반영(SettingsStore EnvironmentObject)
- 워치 진동 강화 재설계: 기본=.start 1방, 톡톡=.start 2방(0.35s),
  지이이잉=.retry 2방 연결(~1.3s), 완주=.retry×3+.success(~2.5s), 세대 토큰 취소
- 도움말 4건·번역(en/ja) 갱신, CLAUDE.md 현행화
- 시뮬 검증: 배지·경고 창·설정 토글, 워치 세팅 페이지(46mm·40mm)·요약 반영,
  3종 빌드 그린·경고 0·l10n 0/0/0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UPmp29DQHY6Ahfss5SRopT
2026-09-03 03:05:28 +09:00

156 lines
6.0 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// WorkoutSettings.swift
// Keging
//
// (··) ,
//
import Foundation
import Combine
/// 3 / .
/// (= / = / = )
nonisolated enum HapticPattern: String, CaseIterable, Identifiable, Codable {
case basic, doubleTap, long
var id: String { rawValue }
var label: String {
switch self {
case .basic: String(localized: "기본")
case .doubleTap: String(localized: "톡톡")
case .long: String(localized: "지이이잉")
}
}
/// Core Haptics ( , , , ) · .
/// (HapticEnginePlayer). 0.28( 0.5 ),
/// 1.2 Core Haptics
var hapticEvents: [(time: Double, duration: Double, intensity: Float, sharpness: Float)] {
switch self {
case .basic: [(0, 0.25, 1.0, 0.55)]
case .doubleTap: [(0, 0.14, 1.0, 0.65), (0.28, 0.14, 1.0, 0.65)]
case .long: [(0, 1.2, 1.0, 0.45)]
}
}
/// (1.0 · 4 )
init?(migrating raw: String?) {
guard let raw else { return nil }
if let direct = HapticPattern(rawValue: raw) {
self = direct
return
}
switch raw {
case "once", "short": self = .basic
case "twice", "thrice", "heartbeat", "rattle": self = .doubleTap
default: return nil
}
}
}
/// . " " .
/// ( Core Haptics · )
nonisolated enum FinishHaptic {
static let events: [(time: Double, duration: Double, intensity: Float, sharpness: Float)] = [
(0, 2.4, 1.0, 0.3)
]
}
/// (HKWorkoutActivityType HealthKitCalls.swift)
nonisolated enum HealthWorkoutType: String, CaseIterable, Identifiable, Codable {
case other, coreTraining
var id: String { rawValue }
var label: String {
switch self {
case .other: String(localized: "기타")
case .coreTraining: String(localized: "코어 트레이닝")
}
}
}
/// = ( ) ×
nonisolated struct WorkoutConfig: Codable, Equatable {
/// (010)
var prepSeconds: Int = 3
var contractSeconds: Int = 10
var relaxSeconds: Int = 5
var reps: Int = 20
/// : = ( ), = ( )
var contractPattern: HapticPattern = .long
var relaxPattern: HapticPattern = .basic
/// (0 = , 1~10)
var effortScore: Int = 2
///
var healthWorkoutType: HealthWorkoutType = .other
init(
prepSeconds: Int = 3,
contractSeconds: Int = 10,
relaxSeconds: Int = 5,
reps: Int = 20,
contractPattern: HapticPattern = .long,
relaxPattern: HapticPattern = .basic,
effortScore: Int = 2,
healthWorkoutType: HealthWorkoutType = .other
) {
self.prepSeconds = prepSeconds
self.contractSeconds = contractSeconds
self.relaxSeconds = relaxSeconds
self.reps = reps
self.contractPattern = contractPattern
self.relaxPattern = relaxPattern
self.effortScore = effortScore
self.healthWorkoutType = healthWorkoutType
}
// JSON decodeIfPresent
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
prepSeconds = try container.decodeIfPresent(Int.self, forKey: .prepSeconds) ?? 3
contractSeconds = try container.decodeIfPresent(Int.self, forKey: .contractSeconds) ?? 10
relaxSeconds = try container.decodeIfPresent(Int.self, forKey: .relaxSeconds) ?? 5
reps = try container.decodeIfPresent(Int.self, forKey: .reps) ?? 20
contractPattern = HapticPattern(migrating: try container.decodeIfPresent(String.self, forKey: .contractPattern)) ?? .long
relaxPattern = HapticPattern(migrating: try container.decodeIfPresent(String.self, forKey: .relaxPattern)) ?? .basic
effortScore = try container.decodeIfPresent(Int.self, forKey: .effortScore) ?? 2
healthWorkoutType = try container.decodeIfPresent(HealthWorkoutType.self, forKey: .healthWorkoutType) ?? .other
}
var totalDuration: TimeInterval { Double(reps * (contractSeconds + relaxSeconds)) }
var summaryText: String {
String(localized: "수축 \(contractSeconds)초 · 이완 \(relaxSeconds)초 · \(reps)")
}
}
@MainActor
final class SettingsStore: ObservableObject {
static let shared = SettingsStore()
// (2026-09-03, 7) .
// ,
@Published var config: WorkoutConfig {
didSet { save() }
}
private static let key = "workout.config.v1"
private init() {
if let data = AppGroup.defaults.data(forKey: Self.key),
let saved = try? JSONDecoder().decode(WorkoutConfig.self, from: data) {
config = saved
} else {
config = WorkoutConfig()
}
}
private func save() {
if let data = try? JSONEncoder().encode(config) {
AppGroup.defaults.set(data, forKey: Self.key)
}
}
}