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
|
|
@ -1,5 +1,4 @@
|
|||
import QtQuick
|
||||
import Quickshell.Services.Mpris
|
||||
import Quickshell.Services.Pipewire
|
||||
import "../services" as S
|
||||
import "../applets" as C
|
||||
|
|
@ -50,12 +49,7 @@ Item {
|
|||
color: Qt.rgba(S.Theme.base01.r, S.Theme.base01.g, S.Theme.base01.b, 0.7)
|
||||
border.color: Qt.rgba(S.Theme.base03.r, S.Theme.base03.g, S.Theme.base03.b, 0.3)
|
||||
border.width: 1
|
||||
visible: (S.Modules.lock.mpris ?? true) && _mprisPlayer !== null
|
||||
|
||||
readonly property var _mprisPlayers: (Mpris.players.values ?? []).filter(p => p.trackTitle || p.playbackState === MprisPlaybackState.Playing || p.playbackState === MprisPlaybackState.Paused)
|
||||
property int _playerIdx: 0
|
||||
readonly property var _mprisPlayer: _mprisPlayers[_playerIdx] ?? _mprisPlayers[0] ?? null
|
||||
readonly property bool _playing: _mprisPlayer?.playbackState === MprisPlaybackState.Playing
|
||||
visible: (S.Modules.lock.mpris ?? true) && S.MprisService.player !== null
|
||||
|
||||
C.MprisApplet {
|
||||
id: _mprisContent
|
||||
|
|
@ -63,15 +57,13 @@ Item {
|
|||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 8
|
||||
player: _mprisCard._mprisPlayer
|
||||
players: _mprisCard._mprisPlayers
|
||||
playing: _mprisCard._playing
|
||||
playerIdx: _mprisCard._playerIdx
|
||||
player: S.MprisService.player
|
||||
players: S.MprisService.players
|
||||
playing: S.MprisService.playing
|
||||
playerIdx: S.MprisService.playerIdx
|
||||
accentColor: S.Theme.base0D
|
||||
cachedArt: _mprisCard._mprisPlayer?.trackArtUrl ?? ""
|
||||
onPlayerSwitched: idx => {
|
||||
_mprisCard._playerIdx = idx;
|
||||
}
|
||||
cachedArt: S.MprisService.player?.trackArtUrl ?? ""
|
||||
onPlayerSwitched: idx => S.MprisService.switchPlayer(idx)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,14 +13,9 @@ M.BarSection {
|
|||
visible: opacity > 0
|
||||
tooltip: ""
|
||||
|
||||
property int _playerIdx: 0
|
||||
readonly property var _players: (Mpris.players.values ?? []).filter(p => p.trackTitle || p.playbackState === MprisPlaybackState.Playing || p.playbackState === MprisPlaybackState.Paused)
|
||||
readonly property MprisPlayer player: _players[_playerIdx] ?? _players[0] ?? null
|
||||
readonly property bool playing: player?.playbackState === MprisPlaybackState.Playing
|
||||
|
||||
// Reset index if current player disappears
|
||||
on_PlayersChanged: if (_playerIdx >= _players.length)
|
||||
_playerIdx = 0
|
||||
readonly property var _players: S.MprisService.players
|
||||
readonly property MprisPlayer player: S.MprisService.player
|
||||
readonly property bool playing: S.MprisService.playing
|
||||
property string _cachedArt: ""
|
||||
property string _artTrack: ""
|
||||
|
||||
|
|
@ -132,9 +127,9 @@ M.BarSection {
|
|||
accentColor: root.accentColor
|
||||
cachedArt: root._cachedArt
|
||||
cavaBars: root._cavaBars
|
||||
playerIdx: root._playerIdx
|
||||
playerIdx: S.MprisService.playerIdx
|
||||
onPlayerSwitched: idx => {
|
||||
root._playerIdx = idx;
|
||||
S.MprisService.switchPlayer(idx);
|
||||
hoverPanel.keepOpen(400);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
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