feat(menubar): 拆分紧凑双页面板并按页采样
This commit is contained in:
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user