feat(menubar): 拆分紧凑双页面板并按页采样

This commit is contained in:
2026-11-08 10:42:55 +08:00
parent ac8b4a7e6a
commit 41dcc497b5
36 changed files with 465 additions and 288 deletions
@@ -2,10 +2,14 @@ import AppKit
import SwiftUI
import Observation
enum PanelPage: Hashable { case overview, processes }
@MainActor @Observable final class PanelPresentation {
fileprivate(set) var isOpen = false
var isPinned = false { didSet { onPinChange?(isPinned) } }
var page: PanelPage = .overview { didSet { if oldValue != page { onPageChange?(page) } } }
@ObservationIgnored var onPinChange: ((Bool) -> Void)?
@ObservationIgnored var onPageChange: ((PanelPage) -> Void)?
}
/// Owns only status-item/window behavior. Sampling and settings are injected by App.
@@ -28,6 +32,7 @@ import Observation
private var isHiding = false
init<Content: View>(installStatusItem: Bool = true, visibility: @escaping (Bool) -> Void,
pageChanged: @escaping (PanelPage) -> Void = { _ in },
menuTitle: @escaping (String) -> String = { $0 },
openSettings: @escaping () -> Void = {},
@ViewBuilder content: @escaping (PanelPresentation) -> Content) {
@@ -51,6 +56,7 @@ import Observation
panel.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
panel.dismiss = { [weak self] in self?.hide() }
presentation.onPinChange = { [weak self] pinned in self?.panel.level = pinned ? .floating : .normal }
presentation.onPageChange = pageChanged
if installStatusItem {
let item = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
item.button?.image = NSImage(named: "BrandMark")
@@ -116,6 +122,7 @@ import Observation
func show() {
guard !panel.isVisible else { panel.makeKeyAndOrderFront(nil); return }
place()
presentation.page = .overview
presentation.isOpen = true
panel.contentView = content(presentation)
panel.level = presentation.isPinned ? .floating : .normal