| 42 | } |
| 43 | |
| 44 | void RunCommandPlugin::receivePacket(const NetworkPacket &np) |
| 45 | { |
| 46 | if (np.get<bool>(QStringLiteral("requestCommandList"), false)) { |
| 47 | sendConfig(); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | if (np.has(QStringLiteral("key"))) { |
| 52 | QJsonDocument commandsDocument = QJsonDocument::fromJson(config()->getByteArray(QStringLiteral("commands"), "{}")); |
| 53 | QJsonObject commands = commandsDocument.object(); |
| 54 | QString key = np.get<QString>(QStringLiteral("key")); |
| 55 | QJsonValue value = commands[key]; |
| 56 | if (value == QJsonValue::Undefined) { |
| 57 | qCWarning(KDECONNECT_PLUGIN_RUNCOMMAND) << key << "is not a configured command"; |
| 58 | } |
| 59 | const QJsonObject commandJson = value.toObject(); |
| 60 | qCInfo(KDECONNECT_PLUGIN_RUNCOMMAND) << "Running:" << COMMAND << ARGS << commandJson[QStringLiteral("command")].toString(); |
| 61 | QProcess::startDetached(QStringLiteral(COMMAND), QStringList{QStringLiteral(ARGS), commandJson[QStringLiteral("command")].toString()}); |
| 62 | } else if (np.has(QStringLiteral("setup"))) { |
| 63 | OpenConfig oc; |
| 64 | oc.openConfiguration(device()->id(), QStringLiteral("kdeconnect_runcommand")); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | void RunCommandPlugin::connected() |
| 69 | { |
nothing calls this directly
no test coverage detected