extract MprisService singleton, share player state between bar and lock screen

This commit is contained in:
Damocles 2026-04-18 10:30:43 +02:00
parent 438362c6d1
commit a7eca009e4
4 changed files with 34 additions and 25 deletions

View file

@ -0,0 +1,21 @@
pragma Singleton
import QtQuick
import Quickshell.Services.Mpris
QtObject {
id: root
readonly property var players: (Mpris.players.values ?? []).filter(p => p.trackTitle || p.playbackState === MprisPlaybackState.Playing || p.playbackState === MprisPlaybackState.Paused)
property int playerIdx: 0
readonly property MprisPlayer player: players[playerIdx] ?? players[0] ?? null
readonly property bool playing: player?.playbackState === MprisPlaybackState.Playing
// Reset index if current player disappears
onPlayersChanged: if (playerIdx >= players.length)
playerIdx = 0
function switchPlayer(idx) {
playerIdx = idx;
}
}