feat(power): 展示电池实际充放电功率并及时响应电源切换

保留电量百分比和连续趋势,按历史采样展示电池、适配器和系统功率。面板可见时读取电池实时功率,插拔电源后立即刷新并复读。
This commit is contained in:
2026-11-15 23:54:19 +08:00
parent 1595af6d13
commit 4b8deb2e48
31 changed files with 739 additions and 119 deletions
+11
View File
@@ -56,6 +56,17 @@ import Observation
precondition(store.effectiveMilliseconds == 1_800_000)
precondition(store.history.samples.last?.breakBefore == true)
store.togglePause()
let pausedCount = store.history.samples.count
store.powerSourceDidChange()
try await Task.sleep(for: .milliseconds(100))
precondition(store.history.samples.count == pausedCount)
store.togglePause()
try await until { store.history.samples.count > pausedCount }
let beforeEvent = store.history.samples.count
store.powerSourceDidChange()
try await until { store.history.samples.count >= beforeEvent + 2 }
precondition(store.effectiveMilliseconds == 1_800_000)
store.togglePause()
let probe = DelayedProcessRead()
let deferred = SystemSampler(processRead: { probe.read(&$0) })
await deferred.setProcessVisible(true)