feat(settings): 新增三语即时切换并记录验收与专项边界
This commit is contained in:
@@ -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