feat(cpu): 图形化展示负载并平滑更新核心占用

This commit is contained in:
2026-11-03 13:31:51 +08:00
parent 96490c4983
commit 81cde73883
4 changed files with 48 additions and 8 deletions
+20 -1
View File
@@ -12,6 +12,7 @@ struct MenuPanelView: View {
@State private var selectedInterface = ""
@State private var showAddresses = false
@State private var showVolumes = false
@Environment(\.accessibilityReduceMotion) private var reduceMotion
private var snapshot: MetricsSnapshot { metrics.snapshot }
private var samples: [TrendSample] { metrics.history.samples }
@@ -144,6 +145,7 @@ struct MenuPanelView: View {
HStack(spacing: 3) {
Text(verbatim: "\(index + 1)").font(.system(size: 9)).frame(width: 12)
MetricProgressBar(value: value, color: coreColor(kind)).frame(height: 7)
.animation(reduceMotion ? nil : .easeInOut(duration: min(0.35, chartInterval * 0.8)), value: value)
}.help((kind.map { coreLabel($0) + Text(verbatim: " · ") } ?? Text("cpu.core")) + Text(verbatim: "\(index + 1): \(MetricFormat.percent(value))"))
.accessibilityLabel(kind.map { coreLabel($0) } ?? Text("cpu.core")).accessibilityValue("\(index + 1): \(MetricFormat.percent(value))")
}
@@ -151,7 +153,24 @@ struct MenuPanelView: View {
} else { Text("metric.waiting").foregroundStyle(.secondary) }
Spacer(minLength: 0)
HStack { line("system.load", snapshot.load.map(MetricFormat.decimal).joined(separator: " / ")).help(Text("cpu.load.help", tableName: "CPUDetails")); Spacer(minLength: 8); Text("panel.uptime").foregroundStyle(.secondary); AnimatedMetricText(value: String(format: "%.1f h", snapshot.uptime / 3600)) }
HStack(spacing: 5) {
HStack(spacing: 5) {
Text("cpu.load.oneMinute", tableName: "CPUDetails").foregroundStyle(.secondary)
if let load = snapshot.load.first, load.isFinite, load >= 0, let count = snapshot.cpu?.cores.count, count > 0 {
MetricProgressBar(value: load / Double(count), color: Color("MetricCPU"))
.frame(minWidth: 20, maxWidth: .infinity).frame(height: 7)
.accessibilityHidden(true)
AnimatedMetricText(value: "\(MetricFormat.decimal(load)) / \(count)")
} else {
Spacer(minLength: 20)
Text(verbatim: "--")
}
}
.help(Text("cpu.load.help", tableName: "CPUDetails"))
Spacer(minLength: 8)
Text("panel.uptime").foregroundStyle(.secondary)
AnimatedMetricText(value: String(format: "%.1f h", snapshot.uptime / 3600))
}
.lineLimit(1).minimumScaleFactor(0.7)
}