Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(media): Event-based updating #16

Merged
merged 6 commits into from
Aug 11, 2024
Merged

Conversation

thomasroodnl
Copy link
Contributor

This PR provides a total rewrite for much of the backend of the media widget, now using event-based instead of timer-base updates. Multiple users have experienced high cpu uasge, NPSMSvc crashes, and other odd behaviour. This was likely caused by the bar spamming the service with update requests. Especially when multiple bars were present (multiple monitors), the amount of requests was large since each widget would do its own requests for updating.

The current implementation subscribes update functions to the winsdk events, and updates from there. The wrapper for winsdk media handling is a singleton to which all media widgets subscribe, meaning that it only makes one windows api call(back) no matter how many widgets.

Remaining known issues: Updates slow on Firefox, which seems to be Firefox not firing update events at immediately (like e.g. Spotify or Arc do).

This commit introduces the rough base for event-based updates to the media widget, instead of timer-based. Multiple users have experienced high cpu uasge, NPSMSvc crashes, and other odd behaviour. This was likely caused by the bar spamming the service with update requests. Especially when multiple bars were present (multiple monitors), the amount of requests was large since each widget would do its own request.

The current implementation subscribes update functions to the `winsdk` events, and updates from there.

Known bugs are that the widget does not hide upon no media, and that the widget does not immediately detect media on launch (a song switch is needed to trigger the first update).
Introduced an event listener for the session change to set the hide/show properly, instead of relying on the media_info change like before.

Known bug: I also identified that the 'C++' error fixed in commit `b08c77a` has resurfaced, due to us making our own event loop, for which the tasks are not killed. It would be better if the bar would call a 'on_close' method for all widgets, and we could put this kind of graceful stopping in there.
Fix this issue (again), now by making sure we clean up the state of the WindowsMedia handling nicely, specifically clearing the callbacks.
Fixed forced updates, which allows detecting already playing media on startup, and fixes the toggle-label behaviour.
Fixed some issues which could freeze the bar because multiple threads were trying to run the async media update. Moved the lock to lock out the full async call to prevent this. Also added thumbnail error handling. This prevents thumbnail cropping errors from crashing the bar, which would occur in some media players which put '-' as title/artist on switch.
I do not yet want to remove the verbose log calls, but I did want to rename them so it is clearer that they originate from the media widget.
@amnweb amnweb merged commit 406650f into amnweb:main Aug 11, 2024
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.

2 participants