diff --git a/autotests/dbusrunnertest.cpp b/autotests/dbusrunnertest.cpp --- a/autotests/dbusrunnertest.cpp +++ b/autotests/dbusrunnertest.cpp @@ -24,6 +24,8 @@ #include "runnermanager.h" #include #include +#include +#include #include @@ -44,6 +46,7 @@ void cleanupTestCase(); void testMatch(); void testMulti(); + void testRequestActionsOnce(); private: QStringList m_filesForCleanup; }; @@ -83,7 +86,7 @@ void DBusRunnerTest::cleanupTestCase() { - for(const QString path: m_filesForCleanup) { + for(const QString &path: qAsConst(m_filesForCleanup)) { QFile::remove(path); } } @@ -173,7 +176,38 @@ process2.waitForFinished(); } +void DBusRunnerTest::testRequestActionsOnce() +{ + QProcess process; + process.start(QFINDTESTDATA("testremoterunner"), QStringList({QStringLiteral("net.krunnertests.dave")})); + QVERIFY(process.waitForStarted()); + QTest::qSleep(500); + RunnerManager m; + auto s = KService::serviceByDesktopPath(QStringLiteral("dbusrunnertest.desktop")); + QVERIFY(s); + m.loadRunner(s); + + // Wait because dbus signal is async + QEventLoop loop; + QTimer t; + QTimer::connect(&t, &QTimer::timeout, &loop, &QEventLoop::quit); + t.start(500); + loop.exec(); + + // Construct a fake match with necesarry data + QueryMatch fakeMatch(m.runner(QStringLiteral("dbusrunnertest"))); + fakeMatch.setId(QStringLiteral("dbusrunnertest_id1")); + fakeMatch.setData(QStringLiteral("net.krunnertests.dave")); + + // We haven't called the prepare slot, if the implementation works + // the actions should alredy be available + auto actions = m.actionsForMatch(fakeMatch); + QCOMPARE(actions.count(), 1); + + process.kill(); + process.waitForFinished(); +} QTEST_MAIN(DBusRunnerTest) diff --git a/autotests/dbusrunnertest.desktop b/autotests/dbusrunnertest.desktop --- a/autotests/dbusrunnertest.desktop +++ b/autotests/dbusrunnertest.desktop @@ -13,3 +13,4 @@ X-Plasma-API=DBus X-Plasma-DBusRunner-Service=net.krunnertests.dave X-Plasma-DBusRunner-Path=/dave +X-Plasma-Request-Actions-Once=true diff --git a/src/data/servicetypes/plasma-runner.desktop b/src/data/servicetypes/plasma-runner.desktop --- a/src/data/servicetypes/plasma-runner.desktop +++ b/src/data/servicetypes/plasma-runner.desktop @@ -68,3 +68,8 @@ [PropertyDef::X-Plasma-DBusRunner-Path] Type=QString + +# Request actions only when the plugin is initialized instead +# of each match session, default is false +[PropertyDef::X-Plasma-Request-Actions-Once] +Type=bool diff --git a/src/dbusrunner.cpp b/src/dbusrunner.cpp --- a/src/dbusrunner.cpp +++ b/src/dbusrunner.cpp @@ -84,8 +84,11 @@ //don't check when not wildcarded, as it could be used with DBus-activation m_matchingServices << requestedServiceName; } - - connect(this, &AbstractRunner::prepare, this, &DBusRunner::requestActions); + if (service->property(QStringLiteral("X-Plasma-Request-Actions-Once")).toBool()) { + requestActions(); + } else { + connect(this, &AbstractRunner::prepare, this, &DBusRunner::requestActions); + } } DBusRunner::~DBusRunner() = default;