feat(menubar): 拆分紧凑双页面板并按页采样
This commit is contained in:
@@ -13,6 +13,7 @@ struct MenuPanelView: View {
|
||||
@State var selectedInterface = ""
|
||||
@State var publicIPAddress: String?
|
||||
@State var showVolumes = false
|
||||
@State private var processState = ProcessTableState()
|
||||
|
||||
var snapshot: MetricsSnapshot { metrics.snapshot }
|
||||
var samples: [TrendSample] { metrics.history.samples }
|
||||
@@ -47,16 +48,19 @@ struct MenuPanelView: View {
|
||||
var body: some View {
|
||||
VStack(spacing: PanelStyle.gap) {
|
||||
if PanelResourceAudit.omitted != "header" { header }
|
||||
if PanelLayout.needsResourceScroll(size: panelSize, rows: rowHeights) {
|
||||
ScrollView { resourceRows }
|
||||
.frame(maxHeight: PanelLayout.resourceHeight(rows: rowHeights))
|
||||
} else {
|
||||
resourceRows
|
||||
}
|
||||
if presentation.isOpen && PanelResourceAudit.omitted != "processes" {
|
||||
PanelProcessSection(metrics: metrics, wide: panelSize.width >= 900).frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.frame(minHeight: 170)
|
||||
if presentation.page == .overview {
|
||||
if PanelLayout.needsResourceScroll(size: panelSize, rows: rowHeights) {
|
||||
ScrollView { resourceRows }
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
} else {
|
||||
resourceRows
|
||||
.frame(maxHeight: .infinity, alignment: .top)
|
||||
}
|
||||
} else if presentation.isOpen && PanelResourceAudit.omitted != "processes" {
|
||||
PanelProcessSection(metrics: metrics, state: processState, wide: panelSize.width >= 800)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
footer
|
||||
}
|
||||
.padding(PanelStyle.padding)
|
||||
.frame(width: panelSize.width, height: panelSize.height)
|
||||
@@ -101,41 +105,62 @@ struct MenuPanelView: View {
|
||||
} else {
|
||||
switch index {
|
||||
case 0: cpuCard
|
||||
case 1: gpuCard
|
||||
case 2: batteryCard
|
||||
case 3: memoryCard
|
||||
case 4: diskCard
|
||||
case 1: batteryCard
|
||||
case 2: gpuCard
|
||||
case 3: diskCard
|
||||
case 4: memoryCard
|
||||
case 5: networkCard
|
||||
default: EmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var brand: some View {
|
||||
HStack(spacing: 6) {
|
||||
Image("BrandMark").renderingMode(.template).resizable().scaledToFit()
|
||||
.frame(width: 22, height: 22)
|
||||
Text("Kymo").font(.system(size: 17, weight: .semibold))
|
||||
}
|
||||
}
|
||||
|
||||
private var pagePicker: some View {
|
||||
Picker("panel.page", selection: Binding(get: { presentation.page }, set: { presentation.page = $0 })) {
|
||||
Text("panel.overview").tag(PanelPage.overview)
|
||||
Text("panel.processes").tag(PanelPage.processes)
|
||||
}
|
||||
.pickerStyle(.segmented).labelsHidden().frame(width: 164)
|
||||
.accessibilityIdentifier("panel.tabs")
|
||||
}
|
||||
|
||||
private var header: some View {
|
||||
HStack(spacing: 10) {
|
||||
Image("BrandMark")
|
||||
.renderingMode(.template)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 24, height: 24)
|
||||
HStack(alignment: .firstTextBaseline, spacing: 2) {
|
||||
Text("Kymo").font(.system(size: 18, weight: .semibold))
|
||||
Text(verbatim: "v\(Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "--")")
|
||||
.font(.system(size: 8, weight: .medium))
|
||||
.foregroundStyle(.secondary)
|
||||
.baselineOffset(7)
|
||||
VStack(spacing: 4) {
|
||||
HStack(spacing: 8) {
|
||||
brand
|
||||
Spacer(minLength: 8)
|
||||
controls
|
||||
}
|
||||
if panelSize.width >= 900 {
|
||||
Rectangle()
|
||||
.fill(.secondary.opacity(0.32))
|
||||
.frame(width: 1, height: 16)
|
||||
.accessibilityHidden(true)
|
||||
Text(verbatim: HardwareIdentity.displayName)
|
||||
.font(.system(size: 11)).foregroundStyle(.secondary).lineLimit(1).truncationMode(.middle)
|
||||
.frame(height: 32)
|
||||
.overlay {
|
||||
if panelSize.width >= 840 { pagePicker }
|
||||
}
|
||||
if panelSize.width < 840 { pagePicker.frame(maxWidth: .infinity).frame(height: 28) }
|
||||
}
|
||||
.frame(height: PanelLayout.headerHeight(width: panelSize.width))
|
||||
.padding(.horizontal, 4)
|
||||
}
|
||||
|
||||
private var footer: some View {
|
||||
HStack {
|
||||
Text(verbatim: HardwareIdentity.displayName)
|
||||
.lineLimit(1).truncationMode(.middle)
|
||||
Spacer(minLength: 8)
|
||||
controls
|
||||
}.padding(.horizontal, 4)
|
||||
HStack(spacing: 4) {
|
||||
Text("panel.uptime")
|
||||
MetricText(value: String(format: "%.1f h", snapshot.uptime / 3600))
|
||||
}
|
||||
}
|
||||
.font(PanelStyle.label).foregroundStyle(.secondary)
|
||||
.frame(height: 18).padding(.horizontal, 4)
|
||||
}
|
||||
|
||||
private var controls: some View {
|
||||
@@ -217,6 +242,7 @@ private struct PanelControlButtonBody<Content: View>: View {
|
||||
/// Keep process publications out of the resource-card observation scope.
|
||||
private struct PanelProcessSection: View {
|
||||
let metrics: MetricsStore
|
||||
let state: ProcessTableState
|
||||
let wide: Bool
|
||||
var body: some View { ProcessTableView(snapshot: metrics.processSnapshot, wide: wide) }
|
||||
var body: some View { ProcessTableView(snapshot: metrics.processSnapshot, energy: metrics.energy, state: state, wide: wide) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user