Fix media status tracking

This commit is contained in:
Jas Singh
2024-06-19 23:50:36 -07:00
parent dd13346e1b
commit d61c50324b

View File

@@ -10,6 +10,11 @@ const Media = () => {
Stopped: 3, Stopped: 3,
}; };
if (value.players.length === 0) {
activePlayer.value = mpris.players[0];
return;
}
const isPlaying = value.players.find( const isPlaying = value.players.find(
(p) => p["play-back-status"] === "Playing", (p) => p["play-back-status"] === "Playing",
); );
@@ -44,20 +49,18 @@ const Media = () => {
const songIcon = Variable(""); const songIcon = Variable("");
const label = Utils.watch( const label = Utils.watch("󰎇 No media playing 󰎇", mpris, "changed", () => {
"󰎇 No media playing 󰎇",
mpris,
"player-changed",
() => {
if (activePlayer.value) { if (activePlayer.value) {
const { track_title, identity } = activePlayer.value; const { track_title, identity } = activePlayer.value;
songIcon.value = getIconForPlayer(identity); songIcon.value = getIconForPlayer(identity);
return track_title.length === 0 ? ` No media playing...` : ` ${track_title}`; return track_title.length === 0
? ` No media playing...`
: ` ${track_title}`;
} else { } else {
songIcon.value = "";
return "󰎇 No media playing 󰎇"; return "󰎇 No media playing 󰎇";
} }
}, });
);
return { return {
component: Widget.Box({ component: Widget.Box({