feat(monitors): 接入统一面板数据与按需进程采样

This commit is contained in:
2026-11-02 22:58:33 +08:00
parent 7df2bbc7c1
commit 604086bbbb
14 changed files with 391 additions and 32 deletions
+10
View File
@@ -24,6 +24,16 @@ nonisolated enum BatteryMonitor {
return max(1, Int((systemSeconds / 60).rounded(.up)))
}
static func availability() -> BatteryAvailability {
guard let info = IOPSCopyPowerSourcesInfo()?.takeRetainedValue(),
let sources = IOPSCopyPowerSourcesList(info)?.takeRetainedValue() as? [CFTypeRef] else { return .failed }
for source in sources {
guard let item = IOPSGetPowerSourceDescription(info, source)?.takeUnretainedValue() as? [String: Any] else { return .failed }
if item[kIOPSTypeKey] as? String == kIOPSInternalBatteryType { return .present }
}
return .absent
}
static func sample() -> BatteryMetrics? {
guard let info = IOPSCopyPowerSourcesInfo()?.takeRetainedValue(),
let sources = IOPSCopyPowerSourcesList(info)?.takeRetainedValue() as? [CFTypeRef] else { return nil }