125 lines
4.5 KiB
Swift
125 lines
4.5 KiB
Swift
import SwiftUI
|
|
import AppKit
|
|
|
|
/// Settings navigation owns presentation only; persisted preferences remain in Core.
|
|
struct AppearanceSettingsView: View {
|
|
@Bindable var preferences: AppearancePreferences
|
|
@Bindable var language: LanguagePreferences
|
|
@Bindable var sampling: SamplingPreferences
|
|
let presentation: SettingsPresentation
|
|
@Environment(\.locale) private var locale
|
|
@State private var selection = SettingsPage.general
|
|
|
|
var body: some View {
|
|
Group {
|
|
switch selection {
|
|
case .general: generalPage
|
|
case .about: aboutPage
|
|
}
|
|
}
|
|
.padding(12)
|
|
.toolbar {
|
|
ToolbarItem(placement: .principal) {
|
|
Picker("settings.title", selection: $selection) {
|
|
Text("settings.general").tag(SettingsPage.general)
|
|
Text("settings.about").tag(SettingsPage.about)
|
|
}
|
|
.pickerStyle(.segmented)
|
|
.labelsHidden()
|
|
}
|
|
}
|
|
.background(SettingsWindowLifecycle(title: AppLocalization.string("settings.title", locale: locale),
|
|
requestID: presentation.requestID))
|
|
.frame(width: 520)
|
|
.frame(minHeight: 420, idealHeight: 460)
|
|
.modifier(AppearanceStyle(preferences: preferences, refreshContentOnChange: true))
|
|
}
|
|
|
|
private var generalPage: some View {
|
|
Form {
|
|
Section {
|
|
LabeledContent("appearance.title") {
|
|
Picker("appearance.title", selection: $preferences.appearance) {
|
|
ForEach(AppAppearance.allCases) { appearance in
|
|
Text(appearance.title).tag(appearance)
|
|
}
|
|
}
|
|
.pickerStyle(.menu)
|
|
.labelsHidden()
|
|
.fixedSize()
|
|
.tint(.primary)
|
|
}
|
|
LabeledContent("language.title") {
|
|
Picker("language.title", selection: $language.language) {
|
|
Text("language.system").tag(AppLanguage.system)
|
|
Text(verbatim: "简体中文").tag(AppLanguage.simplifiedChinese)
|
|
Text(verbatim: "繁體中文").tag(AppLanguage.traditionalChinese)
|
|
Text(verbatim: "English").tag(AppLanguage.english)
|
|
}
|
|
.pickerStyle(.menu)
|
|
.labelsHidden()
|
|
.fixedSize()
|
|
.tint(.primary)
|
|
}
|
|
}
|
|
Section {
|
|
LabeledContent("sampling.background") {
|
|
IntervalControl(milliseconds: $sampling.backgroundMilliseconds)
|
|
}
|
|
Text("sampling.backgroundHelp").font(.callout).foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
.formStyle(.grouped)
|
|
}
|
|
|
|
private var aboutPage: some View {
|
|
Form {
|
|
Section {
|
|
HStack(alignment: .top, spacing: 18) {
|
|
Image("BrandLogo")
|
|
.resizable()
|
|
.scaledToFit()
|
|
.frame(width: 88, height: 88)
|
|
.accessibilityHidden(true)
|
|
VStack(alignment: .leading, spacing: 7) {
|
|
Text(verbatim: "Kymo").font(.title2.bold())
|
|
Text("about.version \(version)")
|
|
.font(.callout)
|
|
.foregroundStyle(.secondary)
|
|
Text("about.description")
|
|
.foregroundStyle(.secondary)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
Spacer(minLength: 0)
|
|
}
|
|
.padding(.vertical, 8)
|
|
}
|
|
}
|
|
.formStyle(.grouped)
|
|
.padding(.horizontal, 12)
|
|
.padding(.top, 6)
|
|
}
|
|
|
|
private var version: String {
|
|
let bundle = Bundle.main
|
|
let version = bundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "--"
|
|
let build = bundle.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "--"
|
|
return "\(version) (\(build))"
|
|
}
|
|
}
|
|
|
|
private extension AppAppearance {
|
|
var title: LocalizedStringKey {
|
|
switch self {
|
|
case .system: "appearance.system"
|
|
case .light: "appearance.light"
|
|
case .dark: "appearance.dark"
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private enum SettingsPage: Hashable {
|
|
case general, about
|
|
}
|