From 7010c66c05c83dd13420a34f8060698d220e8317 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Thu, 2 May 2024 14:31:50 +0200 Subject: [PATCH] Exclude Chrome/Firefox players if Plasma Extension is installed The extension provides a superset of the features of the browser mpris --- plugins/mpriscontrol/mpriscontrolplugin.cpp | 29 ++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/plugins/mpriscontrol/mpriscontrolplugin.cpp b/plugins/mpriscontrol/mpriscontrolplugin.cpp index 79bf39825..0aba2d1a2 100644 --- a/plugins/mpriscontrol/mpriscontrolplugin.cpp +++ b/plugins/mpriscontrol/mpriscontrolplugin.cpp @@ -358,10 +358,37 @@ void MprisControlPlugin::receivePacket(const NetworkPacket &np) } } +QStringList getFilteredPlayerKeys(const QHash &players) +{ + bool hasPlasmaChromiumExtension = false; + bool hasPlasmaFirefoxExtension = false; + for (auto [name, player] : players.asKeyValueRange()) { + QString serviceName = player.serviceName(); + if (serviceName.startsWith(QStringLiteral("org.mpris.MediaPlayer2.plasma-browser-integration"))) { + if (name.contains(QStringLiteral("Firefox"))) { + hasPlasmaFirefoxExtension = true; + } else if (name.contains(QStringLiteral("Chrome")) || name.contains(QStringLiteral("Chromium"))) { + hasPlasmaChromiumExtension = true; + } + } + } + QStringList result; + for (auto [name, player] : players.asKeyValueRange()) { + QString serviceName = player.serviceName(); + if ((hasPlasmaFirefoxExtension && serviceName.startsWith(QStringLiteral("org.mpris.MediaPlayer2.firefox"))) + || (hasPlasmaChromiumExtension && serviceName.startsWith(QStringLiteral("org.mpris.MediaPlayer2.chromium")))) { + continue; // skip + } + result += name; + } + return result; +} + void MprisControlPlugin::sendPlayerList() { + QStringList players = getFilteredPlayerKeys(playerList); NetworkPacket np(PACKET_TYPE_MPRIS); - np.set(QStringLiteral("playerList"), playerList.keys()); + np.set(QStringLiteral("playerList"), players); np.set(QStringLiteral("supportAlbumArtPayload"), true); sendPacket(np); }