feat(menubar): 实现趋势面板外侧详情与三语外观设置
接入有界趋势、平滑滚动、菜单式外侧详情、底部操作与三语文案,装配独立外观设置和 Dock 生命周期。 合并跟随系统外观刷新、自选颜色入口与色块绘制修复,保留用户确认的配色联动、重启保存及滚动验收。 多场景视觉与长期资源验证边界仍记录于 docs。
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
|
||||
/// Keep the app discoverable while its settings window is open, including reopen.
|
||||
struct SettingsWindowLifecycle: NSViewRepresentable {
|
||||
var onClose: () -> Void = {}
|
||||
|
||||
func makeNSView(context: Context) -> WindowObserverView { WindowObserverView() }
|
||||
func updateNSView(_ nsView: WindowObserverView, context: Context) { nsView.onClose = onClose }
|
||||
|
||||
final class WindowObserverView: NSView {
|
||||
override func hitTest(_ point: NSPoint) -> NSView? { nil }
|
||||
var onClose: () -> Void = {}
|
||||
private var tokens: [NSObjectProtocol] = []
|
||||
|
||||
override func viewDidMoveToWindow() {
|
||||
super.viewDidMoveToWindow()
|
||||
for token in tokens { NotificationCenter.default.removeObserver(token) }
|
||||
tokens.removeAll()
|
||||
guard let window else { return }
|
||||
tokens.append(NotificationCenter.default.addObserver(forName: NSWindow.didBecomeKeyNotification,
|
||||
object: window, queue: .main) { _ in
|
||||
MainActor.assumeIsolated {
|
||||
if NSApp.activationPolicy() != .regular { NSApp.setActivationPolicy(.regular) }
|
||||
}
|
||||
})
|
||||
tokens.append(NotificationCenter.default.addObserver(forName: NSWindow.willCloseNotification,
|
||||
object: window, queue: .main) { [weak self] _ in
|
||||
MainActor.assumeIsolated {
|
||||
self?.onClose()
|
||||
NSApp.setActivationPolicy(.accessory)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
deinit { for token in tokens { NotificationCenter.default.removeObserver(token) } }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user