extract MprisService singleton, share player state between bar and lock screen
This commit is contained in:
parent
438362c6d1
commit
a7eca009e4
4 changed files with 34 additions and 25 deletions
21
shell/services/MprisService.qml
Normal file
21
shell/services/MprisService.qml
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,3 +8,4 @@ singleton NotifService 1.0 NotifService.qml
|
|||
NotifItem 1.0 NotifItem.qml
|
||||
singleton LockService 1.0 LockService.qml
|
||||
singleton BacklightService 1.0 BacklightService.qml
|
||||
singleton MprisService 1.0 MprisService.qml
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue