feat(monitors): 接入统一面板数据与按需进程采样
This commit is contained in:
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user