diff --git a/src/contents/ui/Player.qml b/src/contents/ui/Player.qml index 31fe9f4..b008328 100644 --- a/src/contents/ui/Player.qml +++ b/src/contents/ui/Player.qml @@ -6,30 +6,13 @@ QtObject { id: root property var mpris2Model: Mpris.Mpris2Model { - readonly property string sourceName: root.sourceName - function chooseCurrentPlayer() { - if (sourceName === "any") { - currentIndex = 0 - console.debug("setting current source to multiplex"); - return - } - + onRowsInserted: (_, rowIndex) => { const CONTAINER_ROLE = Qt.UserRole + 1 - for (let i = 1; i < rowCount(); i++) { - const player = data(index(i, 0), CONTAINER_ROLE) - if (player.desktopEntry === sourceName) { - currentIndex = i - console.debug(`setting current source to ${player.desktopEntry} (index ${i})`); - return; - } + const player = this.data(this.index(rowIndex, 0), CONTAINER_ROLE) + if (player.desktopEntry === root.sourceName) { + this.currentIndex = rowIndex; } } - onRowsInserted: { - chooseCurrentPlayer() - } - onSourceNameChanged: { - chooseCurrentPlayer() - } } property string sourceName: "any" @@ -94,4 +77,4 @@ QtObject { function setLoopStatus(loopStatus) { mpris2Model.currentPlayer.loopStatus = loopStatus } -} +} \ No newline at end of file diff --git a/src/contents/ui/main.qml b/src/contents/ui/main.qml index 5c83553..1ad2fe9 100644 --- a/src/contents/ui/main.qml +++ b/src/contents/ui/main.qml @@ -8,15 +8,11 @@ import org.kde.plasma.private.mpris as Mpris PlasmoidItem { id: widget - Plasmoid.status: PlasmaCore.Types.HiddenStatus + Plasmoid.status: player.ready ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.HiddenStatus Player { id: player sourceName: plasmoid.configuration.sources[plasmoid.configuration.sourceIndex] - onReadyChanged: { - Plasmoid.status = player.ready ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.HiddenStatus - console.debug(`Player ready changed: ${player.ready} -> plasmoid status changed: ${Plasmoid.status}`) - } } compactRepresentation: Item { @@ -239,4 +235,4 @@ PlasmoidItem { } } -} +} \ No newline at end of file