Skip to content

Defer popover monitor publishes past the SwiftUI update pass#8

Open
nsd97 wants to merge 1 commit into
idevtim:mainfrom
nsd97:contrib/swiftui-publish-hygiene
Open

Defer popover monitor publishes past the SwiftUI update pass#8
nsd97 wants to merge 1 commit into
idevtim:mainfrom
nsd97:contrib/swiftui-publish-hygiene

Conversation

@nsd97

@nsd97 nsd97 commented Jul 19, 2026

Copy link
Copy Markdown

What does this PR do?

Stops flooding the console with Publishing changes from within view updates is not allowed when opening the menu-bar popover, by starting secondary monitors after the hosting view is shown and throttling CpuInfo @Published writes.

Context

  • Issue: N/A (hygiene)
  • Stack: Part 4/4 — standalone off main (no dependency on helper/Ultra)
  • Out of scope: SMAppService helper fix, Ultra, FanTargetCommit no-op skips (those landed with the helper PR), @Observable migration

What changed

  • StatusBarController: show popover / post popoverDidShow first; start CPU/memory/battery/system/FPS monitors on the next main turn
  • CpuInfo: defer @Published assignments off the timer’s immediate update pass; threshold small changes; only grow history when the CPU detail panel is visible
  • AppSettings.syncLaunchAtLogin: skip no-op @Published writes

This matches SwiftUI’s rule that model publishers must not fire during an active view-update pass. Community workarounds (defer to next runloop / skip unchanged publishes) are used here; this is not a migration to @Observable.

Review guide

Start at: ChillMac/App/StatusBarController.swift (popover open path) → ChillMac/Fan/CpuInfo.swiftChillMac/App/AppSettings.swift (syncLaunchAtLogin)

How to test

  1. xcodegen generate && xcodebuild -project ChillMac.xcodeproj -scheme ChillMac build
  2. Run the app from Xcode → open the menu-bar popover repeatedly → confirm the publish-during-update warning flood is gone or greatly reduced
  3. Confirm CPU % / memory / battery cards still update while the popover is open

Checklist

  • Builds without errors (xcodegen generate && xcodebuild -scheme ChillMac build)
  • Unit tests pass — N/A for this PR (no test target changes; run full suite if desired after Add Swift Testing harness and SwiftUI previews #5)
  • Tested manually in the app

Made with Cursor

Start CPU/memory/battery monitors after the hosting view is shown, and throttle CpuInfo @published writes so Observation does not warn mid-body.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant