perf(efficiency): 接入真实CPU能量并隔离展示与采样需求
This commit is contained in:
@@ -237,22 +237,7 @@ extension MenuPanelView {
|
||||
.frame(height: 32)
|
||||
Spacer(minLength: 0)
|
||||
CardSeparator()
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack {
|
||||
Text("battery.highestEnergyProcess").font(PanelStyle.section)
|
||||
Spacer()
|
||||
Text("battery.cpuUsage").foregroundStyle(.secondary)
|
||||
}
|
||||
.font(PanelStyle.label)
|
||||
let energyProcesses = snapshot.processes?.highestCPUProcesses(limit: 3) ?? []
|
||||
if energyProcesses.isEmpty {
|
||||
Text("metric.waiting").foregroundStyle(.secondary)
|
||||
} else {
|
||||
ForEach(energyProcesses) { process in
|
||||
EnergyProcessListRow(process: process)
|
||||
}
|
||||
}
|
||||
}
|
||||
EnergyProcessSection(metrics: metrics)
|
||||
// Reserve the header and all three rows before process sampling completes.
|
||||
.frame(height: 74, alignment: .top)
|
||||
.lineLimit(1)
|
||||
@@ -261,36 +246,3 @@ extension MenuPanelView {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct EnergyProcessListRow: View {
|
||||
let process: ProcessMetrics
|
||||
|
||||
private var progress: Double {
|
||||
guard let value = process.cpu, value.isFinite else { return 0 }
|
||||
return min(max(value, 0), 1)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 5) {
|
||||
ProcessIcon(process: process)
|
||||
Text(verbatim: process.name).lineLimit(1).truncationMode(.middle)
|
||||
.frame(width: 66, alignment: .leading)
|
||||
GeometryReader { proxy in
|
||||
Capsule().fill(.primary.opacity(0.07))
|
||||
.overlay(alignment: .leading) {
|
||||
Capsule().fill(Color("MetricCPU"))
|
||||
.frame(width: proxy.size.width * progress, height: 4)
|
||||
.clipped()
|
||||
}
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
.frame(height: 4)
|
||||
AnimatedMetricText(value: process.cpu.map { String(format: "%.1f%%", $0 * 100) } ?? "--")
|
||||
.foregroundStyle(Color("MetricCPU")).font(PanelStyle.value)
|
||||
.monospacedDigit().frame(width: 39, alignment: .trailing)
|
||||
}
|
||||
.font(PanelStyle.label)
|
||||
.frame(height: 16)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user