perf(menubar): 降低绘制驻留并复用原生进程表与缩略图

This commit is contained in:
2026-11-04 10:39:15 +08:00
parent 1c26fc18f3
commit 065c53622a
28 changed files with 964 additions and 160 deletions
@@ -25,6 +25,7 @@ import Observation
private let menuTitle: (String) -> String
private let openSettings: () -> Void
private var showingStatusMenu = false
private var isHiding = false
init<Content: View>(installStatusItem: Bool = true, visibility: @escaping (Bool) -> Void,
menuTitle: @escaping (String) -> String = { $0 },
@@ -33,7 +34,12 @@ import Observation
self.visibility = visibility
self.menuTitle = menuTitle
self.openSettings = openSettings
self.content = { NSHostingView(rootView: content($0)) }
self.content = {
let host = NSHostingView(rootView: content($0))
// The controller owns the fixed panel frame; content must not negotiate window limits.
host.sizingOptions = []
return host
}
super.init()
panel.title = "Kymo"
panel.isReleasedWhenClosed = false
@@ -126,12 +132,16 @@ import Observation
}
func hide() {
guard !isHiding else { return }
isHiding = true
defer { isHiding = false }
presentation.isOpen = false
panel.orderOut(nil)
#if DEBUG || KYMO_AUDIT
if let content = panel.contentView { lastHiddenContent = content }
#endif
panel.contentView = nil
panel.closeAfterDetachingContent()
visibility(false)
removeMonitors()
}
@@ -197,6 +207,7 @@ final class MonitoringPanel: NSPanel {
var dismiss: (() -> Void)?
override var canBecomeKey: Bool { true }
override var canBecomeMain: Bool { false }
func closeAfterDetachingContent() { super.close() }
override func cancelOperation(_ sender: Any?) { dismiss?() }
override func close() { dismiss?() }
override func performClose(_ sender: Any?) { dismiss?() }