fix(desktop): only update the tray icon when the service state changes - #4017
Open
willherr72 wants to merge 2 commits into
Open
fix(desktop): only update the tray icon when the service state changes#4017willherr72 wants to merge 2 commits into
willherr72 wants to merge 2 commits into
Conversation
The tray refresh loop rebuilt the icon and called set_icon every 250 ms
regardless of state: decoding the bundled PNG, redrawing the status
stripe, and making a cross-process shell call four times a second for
the entire life of the app.
On Windows this eventually fails outright. After several days of uptime
the shell began rejecting every update with ERROR_TIMEOUT ("This
operation returned because the timeout period expired"), which filled
the log at four lines a second and left the tray icon unresponsive.
The loop now compares against the state currently shown and only
touches the tray on a transition. A failed update deliberately does not
record the new state, so the next tick retries rather than leaving the
icon permanently stale.
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.
Issues
Description
The tray icon is rebuilt and reapplied every 250 ms whether or not anything
changed. Each tick decodes the PNG, builds an
Image, and callsset_icon—four times a second, forever, to draw the icon it is already showing.
On macOS and Linux this is merely wasted work. On Windows it becomes a real
fault: after several days of uptime the shell started rejecting every update
with
ERROR_TIMEOUT, which filled the log with one error per tick and left thetray icon unresponsive. Shell_NotifyIcon is rate-sensitive, and a permanent
4 Hz stream of redundant updates is exactly the shape of traffic it gives up on.
This tracks the state the icon is currently showing and only touches the tray
when it actually changes.
One detail worth noting for review: when
set_iconfails, the remembered stateis deliberately left unchanged, so the next tick retries rather than assuming
an update landed that did not.
Found while implementing Windows support, but the bug and the fix are
cross-platform — nothing here is
cfg-gated.How Has This Been Tested?
ERROR_TIMEOUTfromset_iconrepeating once per tick after several days of uptime.
set_iconis called only on an actual transition. Togglingthe highlighter service from the tray menu still updates the icon
immediately, in both directions.
AI Disclosure
Checklist
against the OS tray API; I could not find a way to assert it that would
be more convincing than the manual reproduction above. Happy to add one
if you have a pattern in mind.