// // AppSettingsView.swift // Keging // // 설정 — 앱 테마 등 // import SwiftUI struct AppSettingsView: View { @EnvironmentObject private var settings: SettingsStore @AppStorage("app.theme", store: AppGroup.defaults) private var themeMode = "system" @AppStorage("app.language", store: AppGroup.defaults) private var appLanguage = "system" @AppStorage("app.watchWarn", store: AppGroup.defaults) private var warnNoWatch = true @Environment(\.dismiss) private var dismiss var body: some View { NavigationStack { Form { Section("테마") { Picker("화면 모드", selection: $themeMode) { Text("시스템").tag("system") Text("라이트").tag("light") Text("다크").tag("dark") } .pickerStyle(.segmented) } Section { Picker("언어", selection: $appLanguage) { Text("시스템").tag("system") Text(verbatim: "한국어").tag("ko") Text(verbatim: "English").tag("en") Text(verbatim: "日本語").tag("ja") } } header: { Text("언어") } footer: { Text("언어를 바꾸면 앱을 완전히 종료했다가 다시 실행했을 때 적용돼요.") } Section { Picker("운동 유형", selection: $settings.config.healthWorkoutType) { ForEach(HealthWorkoutType.allCases) { Text($0.label).tag($0) } } Picker("운동 강도 자동 기록", selection: $settings.config.effortScore) { Text("안 함").tag(0) ForEach(1...10, id: \.self) { score in Text(effortLabel(score)).tag(score) } } } header: { Text("애플 건강") } footer: { Text("운동을 끝까지 마치면 그 시간이 위에서 고른 유형으로 애플 건강에 자동 기록되고, 운동 강도(1~10)도 함께 저장돼요. 기록을 원치 않으면 건강 앱에서 케깅의 권한을 끄면 돼요.") } Section { Toggle("워치 미연결 경고", isOn: $warnNoWatch) } header: { Text("애플워치") } footer: { Text("워치가 연결되지 않은 채 시작 버튼을 누르면 확인 창을 띄워요. 워치에서 케깅 앱이 켜져 있을 때만 '연결됨'으로 표시돼요.") } Section { LabeledContent("버전", value: versionText) } footer: { Text("케깅은 광고와 결제가 없는 완전 무료 앱이에요.") } } .navigationTitle("설정") .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .confirmationAction) { Button("완료") { dismiss() } } } .onChange(of: appLanguage) { // 시스템의 앱별 언어 오버라이드 — 다음 실행부터 적용 (하루 다님 검증 방식) if appLanguage == "system" { UserDefaults.standard.removeObject(forKey: "AppleLanguages") } else { UserDefaults.standard.set([appLanguage], forKey: "AppleLanguages") } } } } /// 애플 운동 강도 스케일 표기: 1~3 쉬움 · 4~6 보통 · 7~8 힘듦 · 9~10 전력 private func effortLabel(_ score: Int) -> String { let word: String = switch score { case 1...3: String(localized: "쉬움") case 4...6: String(localized: "보통") case 7...8: String(localized: "힘듦") default: String(localized: "전력") } return String(localized: "\(score) · \(word)") } private var versionText: String { let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "1.0" let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "1" return "\(version) (\(build))" } }