feat(storage): 新增只读 SMART 辅助服务与寿命通电详情
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import Foundation
|
||||
|
||||
/// SMART belongs to the physical storage backing the home volume, not each APFS volume.
|
||||
actor DiskHealthMonitor {
|
||||
private var cached: DiskHealthMetrics?
|
||||
private var nextRead: TimeInterval = 0
|
||||
private var pending: Task<DiskHealthMetrics?, Never>?
|
||||
|
||||
func sample() async -> DiskHealthMetrics? {
|
||||
if let pending { return await pending.value }
|
||||
guard ProcessInfo.processInfo.systemUptime >= nextRead else { return cached }
|
||||
let task = Task { await SMARTServiceClient.read() }
|
||||
pending = task
|
||||
cached = await task.value
|
||||
pending = nil
|
||||
nextRead = ProcessInfo.processInfo.systemUptime + (cached == nil ? 600 : 3600)
|
||||
return cached
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user