feat(settings): 重构液态玻璃设置并更新品牌图标

This commit is contained in:
2026-10-30 16:35:50 +08:00
parent 5c8b6ed136
commit c2f0549568
27 changed files with 449 additions and 43 deletions
+5 -1
View File
@@ -10,7 +10,11 @@ struct MenuBarLabel: View {
Text(verbatim: title)
.monospacedDigit()
} icon: {
Image(systemName: "gauge")
Image("BrandMark")
.renderingMode(.template)
.resizable()
.scaledToFit()
.frame(width: 18, height: 18)
}
.labelStyle(.titleAndIcon)
}
+6 -1
View File
@@ -5,6 +5,7 @@ struct MenuPanelView: View {
let metrics: MetricsStore
let preferences: AppearancePreferences
let keepAwake: KeepAwakeService
let settingsPresentation: SettingsPresentation
@Environment(\.openSettings) private var openSettings
var body: some View {
@@ -210,7 +211,11 @@ struct MenuPanelView: View {
}
.help(metrics.isPaused ? Text("action.resume") : Text("action.pause"))
.accessibilityLabel(metrics.isPaused ? Text("action.resume") : Text("action.pause"))
Button { NSApp.activate(); openSettings() } label: {
Button {
NSApp.setActivationPolicy(.regular)
settingsPresentation.request()
openSettings()
} label: {
Image(systemName: "gearshape").frame(width: 20, height: 20)
}
.help(Text("action.settings")).accessibilityLabel(Text("action.settings"))
@@ -1,30 +1,83 @@
import SwiftUI
import AppKit
/// B-stage appearance controls; general/modules/permissions remain D-stage work.
/// Settings navigation owns presentation only; persisted preferences remain in Core.
struct AppearanceSettingsView: View {
@Bindable var preferences: AppearancePreferences
@Bindable var language: LanguagePreferences
let presentation: SettingsPresentation
@Environment(\.locale) private var locale
@State private var colorPicker = CustomColorPicker()
@State private var selection: SettingsPage? = .appearance
var body: some View {
Form {
Section("settings.language") {
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)
NavigationSplitView {
List(selection: $selection) {
ForEach(SettingsPage.allCases) { page in
Label(page.title, systemImage: page.symbol).tag(page)
}
}
Section("settings.appearance") {
.listStyle(.sidebar)
.navigationSplitViewColumnWidth(min: 160, ideal: 175, max: 200)
.safeAreaInset(edge: .bottom) {
HStack(spacing: 8) {
Image("BrandLogo").resizable().frame(width: 34, height: 34)
Text(verbatim: "Kymo").font(.headline)
Spacer()
}
.padding(12)
}
} detail: {
ScrollView {
VStack(alignment: .leading, spacing: 22) {
Text((selection ?? .appearance).title)
.font(.largeTitle.bold())
switch selection ?? .appearance {
case .appearance: appearancePage
case .language: languagePage
case .about: aboutPage
}
}
.frame(maxWidth: 480, alignment: .leading)
.padding(28)
.frame(maxWidth: .infinity, alignment: .topLeading)
}
.background(.regularMaterial)
}
.navigationSplitViewStyle(.balanced)
.background(SettingsWindowLifecycle(title: AppLocalization.string("settings.title", locale: locale),
requestID: presentation.requestID,
onClose: { colorPicker.close() }))
.onChange(of: preferences.accent) { _, choice in
if choice == .custom {
Task { @MainActor in
await Task.yield()
guard preferences.accent == .custom else { return }
colorPicker.show(for: preferences)
}
} else { colorPicker.close() }
}
.onChange(of: selection) { _, _ in colorPicker.close() }
.frame(minWidth: 680, idealWidth: 740, minHeight: 450, idealHeight: 500)
.modifier(AppearanceStyle(preferences: preferences))
}
private var appearancePage: some View {
glassCard {
VStack(alignment: .leading, spacing: 12) {
Text("appearance.title").font(.headline)
Picker("appearance.title", selection: $preferences.appearance) {
Text("appearance.system").tag(AppAppearance.system)
Text("appearance.light").tag(AppAppearance.light)
Text("appearance.dark").tag(AppAppearance.dark)
}
.labelsHidden()
.pickerStyle(.segmented)
}
Divider()
HStack {
Text("accent.title").font(.headline)
Spacer()
Picker("accent.title", selection: $preferences.accent) {
Text("accent.system").tag(AccentChoice.system)
Text("accent.blue").tag(AccentChoice.blue)
@@ -35,31 +88,84 @@ struct AppearanceSettingsView: View {
Text("accent.pink").tag(AccentChoice.pink)
Text("accent.custom").tag(AccentChoice.custom)
}
if preferences.accent == .custom {
HStack {
Text("accent.custom")
Spacer()
CustomColorWell(preferences: preferences, picker: colorPicker)
.frame(width: 44, height: 26)
}
.labelsHidden()
.fixedSize()
.buttonStyle(.glass)
}
if preferences.accent == .custom {
Divider()
HStack {
Text("accent.custom").font(.headline)
Spacer()
CustomColorWell(preferences: preferences, picker: colorPicker)
.frame(width: 44, height: 26)
}
}
}
.background(SettingsWindowLifecycle(title: AppLocalization.string("settings.title", locale: locale), onClose: { colorPicker.close() }))
.onChange(of: preferences.accent) { _, choice in
if choice == .custom {
Task { @MainActor in
await Task.yield()
guard preferences.accent == .custom else { return }
colorPicker.show(for: preferences)
}
}
else { colorPicker.close() }
}
.onAppear { NSApp.setActivationPolicy(.regular); NSApp.activate() }
.formStyle(.grouped)
.frame(width: 460, height: 340)
.modifier(AppearanceStyle(preferences: preferences))
}
private var languagePage: some View {
glassCard {
HStack {
Text("language.title").font(.headline)
Spacer()
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)
}
.labelsHidden()
.fixedSize()
.buttonStyle(.glass)
}
Text("language.immediate").font(.callout).foregroundStyle(.secondary)
}
}
private var aboutPage: some View {
glassCard {
VStack(spacing: 16) {
Image("BrandLogo").resizable().scaledToFit().frame(width: 112, height: 112)
.accessibilityHidden(true)
Text(verbatim: "Kymo").font(.system(size: 28, weight: .bold))
Text("about.version \(version)").font(.callout).foregroundStyle(.secondary)
Text("about.description").multilineTextAlignment(.center).foregroundStyle(.secondary)
}
.frame(maxWidth: .infinity).padding(.vertical, 16)
}
}
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 func glassCard<Content: View>(@ViewBuilder content: () -> Content) -> some View {
VStack(alignment: .leading, spacing: 18, content: content)
.padding(22)
.frame(maxWidth: .infinity, alignment: .leading)
.glassEffect(.regular, in: .rect(cornerRadius: 22))
}
}
private enum SettingsPage: String, CaseIterable, Identifiable {
case appearance, language, about
var id: String { rawValue }
var title: LocalizedStringKey {
switch self {
case .appearance: "settings.appearance"
case .language: "settings.language"
case .about: "settings.about"
}
}
var symbol: String {
switch self {
case .appearance: "paintpalette"
case .language: "globe"
case .about: "info.circle"
}
}
}
@@ -4,18 +4,25 @@ import AppKit
/// Keep the app discoverable while its settings window is open, including reopen.
struct SettingsWindowLifecycle: NSViewRepresentable {
var title: String
var requestID: UInt64 = 0
var onClose: () -> Void = {}
func makeNSView(context: Context) -> WindowObserverView { WindowObserverView() }
func updateNSView(_ nsView: WindowObserverView, context: Context) {
nsView.onClose = onClose
nsView.title = title
nsView.requestID = requestID
}
final class WindowObserverView: NSView {
override func hitTest(_ point: NSPoint) -> NSView? { nil }
var onClose: () -> Void = {}
var title = "" { didSet { window?.title = title } }
var requestID: UInt64 = 0 {
didSet { if oldValue != requestID { schedulePresentation() } }
}
private var presentationTask: Task<Void, Never>?
private var needsPresentation = false
private var tokens: [NSObjectProtocol] = []
override func viewDidMoveToWindow() {
@@ -24,6 +31,17 @@ struct SettingsWindowLifecycle: NSViewRepresentable {
tokens.removeAll()
guard let window else { return }
window.title = title
window.titlebarAppearsTransparent = true
window.isOpaque = false
window.backgroundColor = .clear
schedulePresentation()
tokens.append(NotificationCenter.default.addObserver(forName: NSApplication.didBecomeActiveNotification,
object: NSApp, queue: .main) { [weak self] _ in
MainActor.assumeIsolated {
guard let self, self.needsPresentation else { return }
self.presentWindow()
}
})
tokens.append(NotificationCenter.default.addObserver(forName: NSWindow.didBecomeKeyNotification,
object: window, queue: .main) { _ in
MainActor.assumeIsolated {
@@ -33,12 +51,36 @@ struct SettingsWindowLifecycle: NSViewRepresentable {
tokens.append(NotificationCenter.default.addObserver(forName: NSWindow.willCloseNotification,
object: window, queue: .main) { [weak self] _ in
MainActor.assumeIsolated {
self?.presentationTask?.cancel()
self?.needsPresentation = false
self?.onClose()
NSApp.setActivationPolicy(.accessory)
}
})
}
deinit { for token in tokens { NotificationCenter.default.removeObserver(token) } }
private func schedulePresentation() {
guard window != nil else { return }
needsPresentation = true
NSApp.setActivationPolicy(.regular)
presentationTask?.cancel()
presentationTask = Task { @MainActor [weak self] in
// Allow accessory → regular and SwiftUI's openSettings ordering to settle.
await Task.yield()
guard !Task.isCancelled, let self, self.needsPresentation else { return }
self.presentWindow()
}
}
private func presentWindow() {
guard let window else { return }
if window.isMiniaturized { window.deminiaturize(nil) }
NSApp.activate()
window.makeKeyAndOrderFront(nil)
window.orderFrontRegardless()
if NSApp.isActive { needsPresentation = false }
}
deinit { presentationTask?.cancel(); for token in tokens { NotificationCenter.default.removeObserver(token) } }
}
}