fix: 灭屏暂停菜单栏定时器,修复菜单打开时速率冻结#3
Merged
Merged
Conversation
- MenuBarStatusController 新增 setupScreenObservers(),监听 screensDidSleep/willSleep 通知后立即 invalidate 菜单栏刷新定时器, didWake/screensDidWake 后重启,消除灭屏状态下持续 ~1.2% 的 CPU 占用 - RunLoop 模式从 .default 改为 .common,确保菜单打开期间(RunLoop 处于 .eventTracking 模式)定时器继续触发,修复速率显示冻结的 bug - updateLabels() 仅在上/下行文本实际变化时才调用 reconcileSpeedLabelWidths(), 减少无流量变化时的冗余文本测宽计算
CI 结果
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
setupScreenObservers(),监听screensDidSleepNotification/willSleepNotification后立即 invalidate 菜单栏刷新定时器;screensDidWakeNotification/didWakeNotification后重启。此前NetworkSpeedMonitor已正确在灭屏时停止采样,但menuBarRefreshTimer仍以max(0.25s, sampleInterval)频率触发主线程文本测宽,导致屏幕关闭后持续 ~1.2% CPU 占用。.default改为.common。菜单打开时 RunLoop 切换到.eventTracking模式,.default模式的定时器不触发,导致速率显示冻结。updateLabels()仅在上/下行文本内容实际变化时才调用reconcileSpeedLabelWidths()(含 2×NSString.size()),消除无流量变化时的空转测宽。Test plan
pmset displaysleepnow关闭屏幕,等待 30 秒后唤醒,Activity Monitor 确认灭屏期间 NetMeter CPU% ≈ 0%,唤醒后速率恢复正常xcodebuild test -scheme NetMeter -destination 'platform=macOS'全部通过