From 9133fa64355004572b9739c879119021e1700d6c Mon Sep 17 00:00:00 2001 From: Nydragon Date: Sat, 28 Sep 2024 01:12:56 +0200 Subject: [PATCH] feat: add a provider for mpris data --- src/provider/Player.qml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/provider/Player.qml diff --git a/src/provider/Player.qml b/src/provider/Player.qml new file mode 100644 index 0000000..204e074 --- /dev/null +++ b/src/provider/Player.qml @@ -0,0 +1,22 @@ +pragma Singleton + +import Quickshell +import Quickshell.Services.Mpris +import QtQuick + +Singleton { + id: player + property MprisPlayer current: player.all[player.index] + property var all: Mpris.players.values + property int index: Mpris.players.values.findIndex(p => p.playbackState === MprisPlaybackState.Playing) + + property var next: () => { + player.index = (player.index + 1) % all.length; + } + property var prev: () => { + const newInd = player.index - 1; + player.index = newInd < 0 ? all.length - 1 : newInd; + } + + property bool isPlaying: current?.playbackState === MprisPlaybackState.Playing +}