Exclude Chrome/Firefox players if Plasma Extension is installed

The extension provides a superset of the features of the browser mpris
This commit is contained in:
Albert Vaca Cintora 2024-05-02 14:31:50 +02:00
parent 150d3eba88
commit 7010c66c05

View file

@ -358,10 +358,37 @@ void MprisControlPlugin::receivePacket(const NetworkPacket &np)
} }
} }
QStringList getFilteredPlayerKeys(const QHash<QString, MprisPlayer> &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() void MprisControlPlugin::sendPlayerList()
{ {
QStringList players = getFilteredPlayerKeys(playerList);
NetworkPacket np(PACKET_TYPE_MPRIS); NetworkPacket np(PACKET_TYPE_MPRIS);
np.set(QStringLiteral("playerList"), playerList.keys()); np.set(QStringLiteral("playerList"), players);
np.set(QStringLiteral("supportAlbumArtPayload"), true); np.set(QStringLiteral("supportAlbumArtPayload"), true);
sendPacket(np); sendPacket(np);
} }