From 81d6a12dfabd8d39debc5687cc3c8c3133d79955 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Fri, 7 Apr 2023 23:52:58 +0200 Subject: [PATCH] Do not load the BigScreen plugin unless on a TV --- core/pluginloader.cpp | 45 +++++++++++++++------ plugins/bigscreen/kdeconnect_bigscreen.json | 3 ++ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/core/pluginloader.cpp b/core/pluginloader.cpp index ec16284eb..7f3efcaa5 100644 --- a/core/pluginloader.cpp +++ b/core/pluginloader.cpp @@ -13,6 +13,7 @@ #include #include +#include "kdeconnectconfig.h" #include "core_debug.h" #include "device.h" #include "kdeconnectplugin.h" @@ -115,28 +116,46 @@ QSet PluginLoader::pluginsForCapabilities(const QSet &incoming { QSet ret; + QString myDeviceType = KdeConnectConfig::instance().deviceType(); + for (const KPluginMetaData &service : qAsConst(plugins)) { + + // Check if the plugin support this device type + const QSet supportedDeviceTypes = KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-SupportedDeviceTypes")).toSet(); + if (!supportedDeviceTypes.isEmpty()) { + if (!supportedDeviceTypes.contains(myDeviceType)) { + qCDebug(KDECONNECT_CORE) << "Not loading plugin" << service.pluginId() << "because this device of type" << myDeviceType << "is not supported. Supports:" << supportedDeviceTypes.toList().join(QStringLiteral(", ")); + continue; + } + } + + // Check if capbilites intersect with the remote device const QSet pluginIncomingCapabilities = KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-SupportedPacketType")).toSet(); const QSet pluginOutgoingCapabilities = KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-OutgoingPacketType")).toSet(); bool capabilitiesEmpty = (pluginIncomingCapabilities.isEmpty() && pluginOutgoingCapabilities.isEmpty()); -#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) - bool capabilitiesIntersect = (outgoing.intersects(pluginIncomingCapabilities) || incoming.intersects(pluginOutgoingCapabilities)); -#else - QSet commonIncoming = incoming; - commonIncoming.intersect(pluginOutgoingCapabilities); - QSet commonOutgoing = outgoing; - commonOutgoing.intersect(pluginIncomingCapabilities); - bool capabilitiesIntersect = (!commonIncoming.isEmpty() || !commonOutgoing.isEmpty()); -#endif + if (!capabilitiesEmpty) { + #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) + bool capabilitiesIntersect = (outgoing.intersects(pluginIncomingCapabilities) || incoming.intersects(pluginOutgoingCapabilities)); + #else + QSet commonIncoming = incoming; + commonIncoming.intersect(pluginOutgoingCapabilities); + QSet commonOutgoing = outgoing; + commonOutgoing.intersect(pluginIncomingCapabilities); + bool capabilitiesIntersect = (!commonIncoming.isEmpty() || !commonOutgoing.isEmpty()); + #endif - if (capabilitiesIntersect || capabilitiesEmpty) { - ret += service.pluginId(); - } else { - qCDebug(KDECONNECT_CORE) << "Not loading plugin" << service.pluginId() << "because device doesn't support it"; + if (!capabilitiesIntersect) { + qCDebug(KDECONNECT_CORE) << "Not loading plugin" << service.pluginId() << "because device doesn't support it"; + continue; + } } + + // If we get here, the plugin can be loaded + ret += service.pluginId(); + } return ret; diff --git a/plugins/bigscreen/kdeconnect_bigscreen.json b/plugins/bigscreen/kdeconnect_bigscreen.json index b2ee2a41e..6496f6803 100644 --- a/plugins/bigscreen/kdeconnect_bigscreen.json +++ b/plugins/bigscreen/kdeconnect_bigscreen.json @@ -87,5 +87,8 @@ ], "X-KdeConnect-SupportedPacketType": [ "kdeconnect.bigscreen.stt" + ], + "X-KdeConnect-SupportedDeviceTypes": [ + "tv" ] }