Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions services/Players.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pragma Singleton

import QtQuick
import QtQml
import Quickshell
import Quickshell.Io
Expand All @@ -22,15 +23,34 @@ Singleton {

Connections {
function onPostTrackChanged() {
nowPlayingTimer.pendingPlayer = root.active;
nowPlayingTimer.restart();
}

target: root.active
}

// Debounce the now playing toast to avoid showing stale metadata.
// Some players (e.g. Spotify) emit postTrackChanged as soon as the track
// ID changes, before the title/artist properties are updated in a follow-up
// D-Bus signal. Waiting a short time ensures the metadata has settled.
// The player is captured at signal time so that an active player switch
// during the debounce window does not show metadata from the wrong player.
Timer {
id: nowPlayingTimer

property MprisPlayer pendingPlayer: null

interval: 300
onTriggered: {
if (!Config.utilities.toasts.nowPlaying) {
return;
}
if (root.active.trackArtist != "" && root.active.trackTitle != "") {
Toaster.toast(qsTr("Now Playing"), qsTr("%1 - %2").arg(root.active.trackArtist).arg(root.active.trackTitle), "music_note");
if (pendingPlayer && pendingPlayer === root.active && pendingPlayer.trackArtist != "" && pendingPlayer.trackTitle != "") {
Toaster.toast(qsTr("Now Playing"), qsTr("%1 - %2").arg(pendingPlayer.trackArtist).arg(pendingPlayer.trackTitle), "music_note");
}
pendingPlayer = null;
}

target: root.active
}

PersistentProperties {
Expand Down