Commit 903cbfd7 authored by David Edmundson's avatar David Edmundson Committed by David Edmundson
Browse files

Add method to run a script from DBus directly

loadScriptInInteractiveConsole requires user interaction which blocks
some purposes, like setting the desktop background from an app.

This runs a given script directly from a passed string without any
prompts.

CCBUG: 217950
REVIEW: 125648
parent eb754470
......@@ -18,5 +18,8 @@
<method name="loadKWinScriptInInteractiveConsole">
<arg name="script" type="s" direction="in"/>
</method>
<method name="evaluateScript">
<arg name="script" type="s" direction="in"/>
</method>
</interface>
</node>
......@@ -1210,6 +1210,31 @@ void ShellCorona::loadKWinScriptInInteractiveConsole(const QString &script)
}
}
void ShellCorona::evaluateScript(const QString &script) {
if (immutability() != Plasma::Types::Mutable) {
if (calledFromDBus()) {
sendErrorReply(QDBusError::Failed, QStringLiteral("Widgets are locked"));
}
return;
}
WorkspaceScripting::ScriptEngine scriptEngine(this);
connect(&scriptEngine, &WorkspaceScripting::ScriptEngine::printError, this,
[](const QString &msg) {
qWarning() << msg;
});
connect(&scriptEngine, &WorkspaceScripting::ScriptEngine::print, this,
[](const QString &msg) {
qDebug() << msg;
});
scriptEngine.evaluateScript(script);
if (scriptEngine.hasUncaughtException() && calledFromDBus()) {
sendErrorReply(QDBusError::Failed, scriptEngine.uncaughtException().toString());
}
}
void ShellCorona::interactiveConsoleVisibilityChanged(bool visible)
{
if (!visible) {
......
......@@ -27,6 +27,8 @@
#include <QSet>
#include <QTimer>
#include <QDBusVariant>
#include <QDBusContext>
#include <KPackage/Package>
......@@ -66,7 +68,7 @@ namespace KWayland
}
}
class ShellCorona : public Plasma::Corona
class ShellCorona : public Plasma::Corona, QDBusContext
{
Q_OBJECT
Q_PROPERTY(QString shell READ shell WRITE setShell)
......@@ -139,6 +141,7 @@ public Q_SLOTS:
void showInteractiveKWinConsole();
void loadKWinScriptInInteractiveConsole(const QString &script);
void toggleActivityManager();
void evaluateScript(const QString &string);
Plasma::Containment *addPanel(const QString &plugin);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment