feat(monitors): 为无内置电池的 Mac 采样整机即时功率

加入整机功率采样、XPC 读取和历史记录,并覆盖无电池设备的采样分支。
This commit is contained in:
2026-11-15 22:03:46 +08:00
parent e2f88023d6
commit c886c4227d
10 changed files with 58 additions and 2 deletions
+5
View File
@@ -3,6 +3,7 @@ import Foundation
private actor CPUTemperatureReader {
private let monitor = CPUTemperatureMonitor()
private let gpuMonitor = CPUTemperatureMonitor(zone: .gpu)
func sampleSystemPower() -> Double? { monitor.sampleSystemPower() }
func sampleFans() -> [Double?]? { monitor.sampleFans() }
func sampleGPU() -> Double? { gpuMonitor.sample() }
@@ -14,6 +15,10 @@ private actor CPUTemperatureReader {
final class SMARTService: NSObject, SMARTServiceProtocol {
private let temperatureReader = CPUTemperatureReader()
func readSystemPower(withReply reply: @escaping (NSNumber?) -> Void) {
Task { reply(await temperatureReader.sampleSystemPower().map(NSNumber.init(value:))) }
}
func readSensors(cpu: Bool, gpu: Bool, fans: Bool,
withReply reply: @escaping (NSNumber?, NSNumber?, [NSNumber]?) -> Void) {
Task {