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
@@ -29,15 +29,12 @@ nonisolated struct ProcessEnergyMonitor: Sendable {
if let (power, seconds) = Self.watts(current: reading, previous: previous[reading.id], maximumInterval: maximumInterval) {
measured += 1
let usage = ProcessEnergyUsage(process: process, watts: power, seconds: seconds)
let index = usages.firstIndex {
$0.watts < power || ($0.watts == power && $0.id.pid > process.id.pid)
} ?? usages.endIndex
usages.insert(usage, at: index)
if usages.count > 3 { usages.removeLast() }
usages.append(usage)
}
}
}
previous = next // Failed / missing readings invalidate the old baseline.
usages.sort { $0.watts == $1.watts ? $0.id.pid < $1.id.pid : $0.watts > $1.watts }
let state: ProcessEnergySnapshot.State
if capability == .unsupported { state = .unsupported }
else if capability == .unavailable || processes.failed || (capability == .verifiedCPU && next.isEmpty) { state = .unavailable }