Remove request packets from Battery and Connectivity Report plugins

We already send updates right after connecting and once there's a
change, so this was redundant.
This commit is contained in:
Albert Vaca Cintora 2023-07-17 14:14:11 +02:00
parent 619904b317
commit 2a1c751ef4
6 changed files with 39 additions and 58 deletions

View file

@ -19,31 +19,12 @@
K_PLUGIN_CLASS_WITH_JSON(BatteryPlugin, "kdeconnect_battery.json") K_PLUGIN_CLASS_WITH_JSON(BatteryPlugin, "kdeconnect_battery.json")
BatteryPlugin::BatteryPlugin(QObject *parent, const QVariantList &args)
: KdeConnectPlugin(parent, args)
{
}
int BatteryPlugin::charge() const
{
return m_charge;
}
bool BatteryPlugin::isCharging() const
{
return m_isCharging;
}
void BatteryPlugin::connected()
{
// We've just connected. Request battery information from the remote device...
NetworkPacket np(PACKET_TYPE_BATTERY_REQUEST, {{QStringLiteral("request"), true}});
sendPacket(np);
// ...and then figure out whether we have any batteries
const auto batteryDevice = Solid::DeviceInterface::Type::Battery; const auto batteryDevice = Solid::DeviceInterface::Type::Battery;
const auto primary = Solid::Battery::BatteryType::PrimaryBattery; const auto primary = Solid::Battery::BatteryType::PrimaryBattery;
BatteryPlugin::BatteryPlugin(QObject *parent, const QVariantList &args)
: KdeConnectPlugin(parent, args)
{
QList<Solid::Device> batteries = Solid::Device::listFromQuery(Solid::Predicate(batteryDevice, QStringLiteral("type"), primary)); QList<Solid::Device> batteries = Solid::Device::listFromQuery(Solid::Predicate(batteryDevice, QStringLiteral("type"), primary));
if (batteries.isEmpty()) { if (batteries.isEmpty()) {
@ -59,7 +40,20 @@ void BatteryPlugin::connected()
connect(chosen, &Solid::Battery::chargeStateChanged, this, &BatteryPlugin::slotChargeChanged); connect(chosen, &Solid::Battery::chargeStateChanged, this, &BatteryPlugin::slotChargeChanged);
connect(chosen, &Solid::Battery::chargePercentChanged, this, &BatteryPlugin::slotChargeChanged); connect(chosen, &Solid::Battery::chargePercentChanged, this, &BatteryPlugin::slotChargeChanged);
}
int BatteryPlugin::charge() const
{
return m_charge;
}
bool BatteryPlugin::isCharging() const
{
return m_isCharging;
}
void BatteryPlugin::connected()
{
// Explicitly send the current charge // Explicitly send the current charge
slotChargeChanged(); slotChargeChanged();
} }
@ -73,9 +67,6 @@ void BatteryPlugin::slotChargeChanged()
int batteryQuantity = 0; int batteryQuantity = 0;
int cumulativeCharge = 0; int cumulativeCharge = 0;
const auto batteryDevice = Solid::DeviceInterface::Type::Battery;
const auto primary = Solid::Battery::BatteryType::PrimaryBattery;
QList<Solid::Device> batteries = Solid::Device::listFromQuery(Solid::Predicate(batteryDevice, QStringLiteral("type"), primary)); QList<Solid::Device> batteries = Solid::Device::listFromQuery(Solid::Predicate(batteryDevice, QStringLiteral("type"), primary));
for (auto device : batteries) { for (auto device : batteries) {
@ -117,6 +108,10 @@ void BatteryPlugin::slotChargeChanged()
bool BatteryPlugin::receivePacket(const NetworkPacket &np) bool BatteryPlugin::receivePacket(const NetworkPacket &np)
{ {
if (PACKET_TYPE_BATTERY != np.type()) {
return false;
}
m_isCharging = np.get<bool>(QStringLiteral("isCharging"), false); m_isCharging = np.get<bool>(QStringLiteral("isCharging"), false);
m_charge = np.get<int>(QStringLiteral("currentCharge"), -1); m_charge = np.get<int>(QStringLiteral("currentCharge"), -1);
const int thresholdEvent = np.get<int>(QStringLiteral("thresholdEvent"), (int)ThresholdNone); const int thresholdEvent = np.get<int>(QStringLiteral("thresholdEvent"), (int)ThresholdNone);

View file

@ -10,7 +10,6 @@
#include <core/kdeconnectplugin.h> #include <core/kdeconnectplugin.h>
#define PACKET_TYPE_BATTERY QStringLiteral("kdeconnect.battery") #define PACKET_TYPE_BATTERY QStringLiteral("kdeconnect.battery")
#define PACKET_TYPE_BATTERY_REQUEST QStringLiteral("kdeconnect.battery.request")
class BatteryPlugin : public KdeConnectPlugin class BatteryPlugin : public KdeConnectPlugin
{ {

View file

@ -134,11 +134,9 @@
"Website": "https://albertvaka.wordpress.com" "Website": "https://albertvaka.wordpress.com"
}, },
"X-KdeConnect-OutgoingPacketType": [ "X-KdeConnect-OutgoingPacketType": [
"kdeconnect.battery", "kdeconnect.battery"
"kdeconnect.battery.request"
], ],
"X-KdeConnect-SupportedPacketType": [ "X-KdeConnect-SupportedPacketType": [
"kdeconnect.battery", "kdeconnect.battery"
"kdeconnect.battery.request"
] ]
} }

View file

@ -32,14 +32,14 @@ int ConnectivityReportPlugin::cellularNetworkStrength() const
void ConnectivityReportPlugin::connected() void ConnectivityReportPlugin::connected()
{ {
// We've just connected. Request connectivity_report information from the remote device...
NetworkPacket np(PACKET_TYPE_CONNECTIVITY_REPORT_REQUEST, {{QStringLiteral("request"), true}});
sendPacket(np);
} }
bool ConnectivityReportPlugin::receivePacket(const NetworkPacket &np) bool ConnectivityReportPlugin::receivePacket(const NetworkPacket &np)
{ {
if (np.type() == PACKET_TYPE_CONNECTIVITY_REPORT) { if (PACKET_TYPE_CONNECTIVITY_REPORT != np.type()) {
return false;
}
auto subscriptions = np.get<QVariantMap>(QStringLiteral("signalStrengths"), QVariantMap()); auto subscriptions = np.get<QVariantMap>(QStringLiteral("signalStrengths"), QVariantMap());
if (!subscriptions.isEmpty()) { if (!subscriptions.isEmpty()) {
auto networkInfo = subscriptions.first().toMap(); auto networkInfo = subscriptions.first().toMap();
@ -54,8 +54,6 @@ bool ConnectivityReportPlugin::receivePacket(const NetworkPacket &np)
Q_EMIT refreshed(m_cellularNetworkType, m_cellularNetworkStrength); Q_EMIT refreshed(m_cellularNetworkType, m_cellularNetworkStrength);
} }
} }
}
return true; return true;
} }

View file

@ -32,13 +32,6 @@
*/ */
#define PACKET_TYPE_CONNECTIVITY_REPORT QStringLiteral("kdeconnect.connectivity_report") #define PACKET_TYPE_CONNECTIVITY_REPORT QStringLiteral("kdeconnect.connectivity_report")
/**
* Packet sent to request the current connectivity state
* <p>
* The request packet shall contain no body
*/
#define PACKET_TYPE_CONNECTIVITY_REPORT_REQUEST QStringLiteral("kdeconnect.connectivity_report.request")
class ConnectivityReportPlugin : public KdeConnectPlugin class ConnectivityReportPlugin : public KdeConnectPlugin
{ {
Q_OBJECT Q_OBJECT

View file

@ -129,9 +129,7 @@
], ],
"Version": "1.0" "Version": "1.0"
}, },
"X-KdeConnect-OutgoingPacketType": [ "X-KdeConnect-OutgoingPacketType": [],
"kdeconnect.connectivity_report.request"
],
"X-KdeConnect-SupportedPacketType": [ "X-KdeConnect-SupportedPacketType": [
"kdeconnect.connectivity_report" "kdeconnect.connectivity_report"
] ]