refactor(project): 清理闲置展示链路与重复采样状态

This commit is contained in:
2026-11-09 00:41:09 +08:00
parent 7b3abe37c5
commit b73d51c953
57 changed files with 210 additions and 2822 deletions
+2 -4
View File
@@ -14,7 +14,6 @@ final class MetricsStore {
private(set) var processUpdatesRequested = false
private(set) var slowMetricsRequested = true
let sampling: SamplingPreferences
private let energyEnabled: Bool
private var panelDemand: Bool { isPanelVisible && !isDisplaySleeping }
private var processDemand: Bool { panelDemand && processUpdatesRequested }
var effectiveMilliseconds: Int { panelDemand ? sampling.panelMilliseconds : sampling.backgroundMilliseconds }
@@ -31,9 +30,8 @@ final class MetricsStore {
@ObservationIgnored private var needsHistoryBoundary = true
@ObservationIgnored private var lastPublishedAt: ContinuousClock.Instant?
init(sampling: SamplingPreferences? = nil, sampler: SystemSampler = SystemSampler(), energyEnabled: Bool = true) {
init(sampling: SamplingPreferences? = nil, sampler: SystemSampler = SystemSampler()) {
self.sampler = sampler
self.energyEnabled = energyEnabled
self.sampling = sampling ?? SamplingPreferences()
self.sampling.onChange = { [weak self] in
guard let self, !self.isPaused,
@@ -78,7 +76,7 @@ final class MetricsStore {
var next = await sampler.sample(includeProcesses: self?.processDemand == true,
includeSlowMetrics: self?.panelDemand == true && self?.slowMetricsRequested == true,
maximumEnergyInterval: max(30, Double(self?.effectiveMilliseconds ?? 2000) / 500),
includeEnergy: self?.energyEnabled == true, demandRevision: visibleGeneration, processUpdate: { [weak self] processes in
demandRevision: visibleGeneration, processUpdate: { [weak self] processes in
Task { @MainActor [weak self] in
guard let self, self.visibilityGeneration == visibleGeneration,
self.processDemand, !self.isPaused, !self.isSystemSleeping else { return }