fix: debounce now playing toast to show correct track metadata#1338
fix: debounce now playing toast to show correct track metadata#1338endafk wants to merge 5 commits into
Conversation
Some MPRIS players (e.g. Spotify) emit postTrackChanged as soon as the track ID changes over D-Bus, before the title/artist properties are updated in a follow-up signal. This caused the now playing notification to display the previous track's metadata instead of the new one. Fix by deferring the toast via a 300ms Timer. If postTrackChanged fires again within that window (second metadata update), the timer restarts, so only one notification is shown once the metadata has settled.
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect “Now Playing” toast metadata by debouncing MPRIS postTrackChanged handling so notifications fire after player metadata settles (notably for Spotify’s two-phase D-Bus updates).
Changes:
- Route
postTrackChangedhandling through a 300msTimerto debounce the toast. - Add
QtQuickimport to useTimer.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Hmm, I use spotify and the media toasts work fine. There is only one on song change and it displays the track correctly. |
I pretty use Gapless(g4music) and chrome(Youtube and Youtube Music) and I get a toast of the previous song whenever I use next. Whenever music stops. I also receive a toast of the music that was playing before I stoppped. Everytime there is an update, I have to redo the 300ms delay manually on the qml file |
Problem
When pressing next/previous, the now playing toast shows the previous track instead of the new one.
Root cause
Some MPRIS players (notably Spotify and Google Chrome) emit
postTrackChangedin two D-Bus phases:mpris:trackidupdates to the new track, butxesam:title/xesam:artiststill carry the old track's valuesonPostTrackChangedwas firing immediately on phase 1, reading stale metadata and displaying the wrong song in the notification.Fix
Defer the toast via a
Timer { interval: 300 }. The handler now callsnowPlayingTimer.restart()instead of showing the toast directly. IfpostTrackChangedfires again within 300ms (the second metadata update), the timer resets — so only one notification fires, after the metadata has settled.