feat(settings): 新增三语即时切换并记录验收与专项边界
This commit is contained in:
@@ -4,10 +4,20 @@ import AppKit
|
||||
/// B-stage appearance controls; general/modules/permissions remain D-stage work.
|
||||
struct AppearanceSettingsView: View {
|
||||
@Bindable var preferences: AppearancePreferences
|
||||
@Bindable var language: LanguagePreferences
|
||||
@Environment(\.locale) private var locale
|
||||
@State private var colorPicker = CustomColorPicker()
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
Section("settings.appearance") {
|
||||
Picker("appearance.title", selection: $preferences.appearance) {
|
||||
Text("appearance.system").tag(AppAppearance.system)
|
||||
@@ -35,7 +45,7 @@ struct AppearanceSettingsView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.background(SettingsWindowLifecycle(onClose: { colorPicker.close() }))
|
||||
.background(SettingsWindowLifecycle(title: AppLocalization.string("settings.title", locale: locale), onClose: { colorPicker.close() }))
|
||||
.onChange(of: preferences.accent) { _, choice in
|
||||
if choice == .custom {
|
||||
Task { @MainActor in
|
||||
@@ -48,7 +58,7 @@ struct AppearanceSettingsView: View {
|
||||
}
|
||||
.onAppear { NSApp.setActivationPolicy(.regular); NSApp.activate() }
|
||||
.formStyle(.grouped)
|
||||
.frame(width: 420, height: 240)
|
||||
.frame(width: 460, height: 340)
|
||||
.modifier(AppearanceStyle(preferences: preferences))
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,15 @@ import AppKit
|
||||
struct CustomColorWell: NSViewRepresentable {
|
||||
let preferences: AppearancePreferences
|
||||
let picker: CustomColorPicker
|
||||
@Environment(\.locale) private var locale
|
||||
|
||||
func makeNSView(context: Context) -> SwatchButton {
|
||||
let button = SwatchButton()
|
||||
button.setAccessibilityLabel(String(localized: "accent.custom"))
|
||||
return button
|
||||
}
|
||||
|
||||
func updateNSView(_ button: SwatchButton, context: Context) {
|
||||
button.setAccessibilityLabel(AppLocalization.string("accent.custom", locale: locale))
|
||||
button.open = { picker.show(for: preferences) }
|
||||
button.swatchColor = NSColor(srgbRed: preferences.red, green: preferences.green, blue: preferences.blue, alpha: 1)
|
||||
}
|
||||
|
||||
@@ -3,14 +3,19 @@ import AppKit
|
||||
|
||||
/// Keep the app discoverable while its settings window is open, including reopen.
|
||||
struct SettingsWindowLifecycle: NSViewRepresentable {
|
||||
var title: String
|
||||
var onClose: () -> Void = {}
|
||||
|
||||
func makeNSView(context: Context) -> WindowObserverView { WindowObserverView() }
|
||||
func updateNSView(_ nsView: WindowObserverView, context: Context) { nsView.onClose = onClose }
|
||||
func updateNSView(_ nsView: WindowObserverView, context: Context) {
|
||||
nsView.onClose = onClose
|
||||
nsView.title = title
|
||||
}
|
||||
|
||||
final class WindowObserverView: NSView {
|
||||
override func hitTest(_ point: NSPoint) -> NSView? { nil }
|
||||
var onClose: () -> Void = {}
|
||||
var title = "" { didSet { window?.title = title } }
|
||||
private var tokens: [NSObjectProtocol] = []
|
||||
|
||||
override func viewDidMoveToWindow() {
|
||||
@@ -18,6 +23,7 @@ struct SettingsWindowLifecycle: NSViewRepresentable {
|
||||
for token in tokens { NotificationCenter.default.removeObserver(token) }
|
||||
tokens.removeAll()
|
||||
guard let window else { return }
|
||||
window.title = title
|
||||
tokens.append(NotificationCenter.default.addObserver(forName: NSWindow.didBecomeKeyNotification,
|
||||
object: window, queue: .main) { _ in
|
||||
MainActor.assumeIsolated {
|
||||
|
||||
Reference in New Issue
Block a user