feat(menubar): 新增可配置的实时菜单栏指标与设置预览
使用竖条显示 CPU、GPU、内存与磁盘占用,分行展示上传和下载速率。支持全选、取消全选与空选恢复品牌图标,实时指标跟随面板刷新间隔。
This commit is contained in:
@@ -15,12 +15,14 @@ final class MetricsStore {
|
||||
private(set) var slowMetricsRequested = true
|
||||
let sampling: SamplingPreferences
|
||||
private var panelDemand: Bool { isPanelVisible && !isDisplaySleeping }
|
||||
private var menuBarEnabled = false
|
||||
private var liveDemand: Bool { panelDemand || (menuBarEnabled && !isDisplaySleeping) }
|
||||
private var processDemand: Bool { panelDemand && processUpdatesRequested }
|
||||
var effectiveMilliseconds: Int { panelDemand ? sampling.panelMilliseconds : sampling.backgroundMilliseconds }
|
||||
private var hasSamplingDemand: Bool { !isSystemSleeping && (panelDemand || sampling.backgroundEnabled) }
|
||||
var effectiveMilliseconds: Int { liveDemand ? sampling.panelMilliseconds : sampling.backgroundMilliseconds }
|
||||
private var hasSamplingDemand: Bool { !isSystemSleeping && (liveDemand || sampling.backgroundEnabled) }
|
||||
// Permit timer coalescing without changing the requested cadence or delta timestamps.
|
||||
private var schedulingTolerance: Duration {
|
||||
.milliseconds(min(effectiveMilliseconds / 10, panelDemand ? 200 : 1_000))
|
||||
.milliseconds(min(effectiveMilliseconds / 10, liveDemand ? 200 : 1_000))
|
||||
}
|
||||
@ObservationIgnored private var generation = 0
|
||||
@ObservationIgnored private var visibilityGeneration = 0
|
||||
@@ -36,7 +38,7 @@ final class MetricsStore {
|
||||
self.sampling.onChange = { [weak self] in
|
||||
guard let self, !self.isPaused,
|
||||
self.effectiveMilliseconds != self.scheduledInterval || self.hasSamplingDemand != (self.task != nil) else { return }
|
||||
self.reschedule(reset: false, sampleImmediately: false)
|
||||
self.reschedule(reset: self.task == nil, sampleImmediately: self.task == nil)
|
||||
}
|
||||
start()
|
||||
}
|
||||
@@ -134,14 +136,25 @@ final class MetricsStore {
|
||||
|
||||
func setDisplaySleeping(_ sleeping: Bool) {
|
||||
guard sleeping != isDisplaySleeping else { return }
|
||||
let wasActive = hasSamplingDemand
|
||||
isDisplaySleeping = sleeping
|
||||
updateDemand(reset: !sampling.backgroundEnabled, sampleImmediately: panelDemand)
|
||||
updateDemand(reset: !wasActive || !hasSamplingDemand, sampleImmediately: liveDemand)
|
||||
}
|
||||
|
||||
func setPanelVisible(_ visible: Bool) {
|
||||
guard isPanelVisible != visible else { return }
|
||||
let wasActive = hasSamplingDemand
|
||||
isPanelVisible = visible
|
||||
updateDemand(reset: !sampling.backgroundEnabled, sampleImmediately: panelDemand)
|
||||
updateDemand(reset: !wasActive || !hasSamplingDemand, sampleImmediately: panelDemand)
|
||||
}
|
||||
|
||||
func setMenuBarEnabled(_ enabled: Bool) {
|
||||
guard menuBarEnabled != enabled else { return }
|
||||
let wasLive = liveDemand
|
||||
let wasActive = hasSamplingDemand
|
||||
menuBarEnabled = enabled
|
||||
guard wasLive != liveDemand, !isPaused, !isSystemSleeping else { return }
|
||||
reschedule(reset: !wasActive || !hasSamplingDemand, sampleImmediately: enabled)
|
||||
}
|
||||
|
||||
/// The caller supplies data needs, without introducing UI types into Core.
|
||||
|
||||
Reference in New Issue
Block a user