From 43174a977105fc52009b1272e345ba7fa36751b4 Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Mon, 16 Oct 2023 12:59:20 +0200 Subject: [PATCH] Remove X-Plasma-MainScript from C++ codepaths --- .../integration/scripting/minimizeall_test.cpp | 6 ++---- src/kcms/tabbox/main.cpp | 10 +++------- src/plugins/kdecorations/aurorae/src/aurorae.cpp | 5 ++--- src/scripting/scriptedeffect.cpp | 14 ++++---------- src/scripting/scripting.cpp | 7 ++++--- 5 files changed, 15 insertions(+), 27 deletions(-) diff --git a/autotests/integration/scripting/minimizeall_test.cpp b/autotests/integration/scripting/minimizeall_test.cpp index 921a0d2e52..f814c97bcc 100644 --- a/autotests/integration/scripting/minimizeall_test.cpp +++ b/autotests/integration/scripting/minimizeall_test.cpp @@ -70,10 +70,8 @@ static QString locateMainScript(const QString &pluginName) if (offers.isEmpty()) { return QString(); } - const KPluginMetaData &metaData = offers.first(); - const QString mainScriptFileName = metaData.value(QStringLiteral("X-Plasma-MainScript")); - const QFileInfo metaDataFileInfo(metaData.fileName()); - return metaDataFileInfo.path() + QLatin1String("/contents/") + mainScriptFileName; + const QFileInfo metaDataFileInfo(offers.first().fileName()); + return metaDataFileInfo.path() + QLatin1String("/contents/code/main.js"); } void MinimizeAllScriptTest::init() diff --git a/src/kcms/tabbox/main.cpp b/src/kcms/tabbox/main.cpp index 5d51acff37..c8eac08ad6 100644 --- a/src/kcms/tabbox/main.cpp +++ b/src/kcms/tabbox/main.cpp @@ -167,14 +167,10 @@ void KWinTabBoxConfig::initLayoutLists() for (const auto &offer : offers) { const QString pluginName = offer.pluginId(); - if (offer.value("X-Plasma-API") != "declarativeappletscript") { - continue; - } - const QString scriptName = offer.value("X-Plasma-MainScript"); const QString scriptFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, - QLatin1String("kwin/tabbox/") + pluginName + QLatin1String("/contents/") - + scriptName); - if (scriptFile.isNull()) { + QLatin1String("kwin/tabbox/") + pluginName + QLatin1String("/contents/ui/main.qml")); + if (scriptFile.isEmpty()) { + qWarning() << "scriptfile is null" << pluginName; continue; } diff --git a/src/plugins/kdecorations/aurorae/src/aurorae.cpp b/src/plugins/kdecorations/aurorae/src/aurorae.cpp index f7fcb26c86..e38f795b24 100644 --- a/src/plugins/kdecorations/aurorae/src/aurorae.cpp +++ b/src/plugins/kdecorations/aurorae/src/aurorae.cpp @@ -156,10 +156,9 @@ QQmlComponent *Helper::loadComponent(const QString &themeName) // TODO: what to do in error case? return nullptr; } - const KPluginMetaData &service = offers.first(); + const KPluginMetaData service = offers.first(); const QString pluginName = service.pluginId(); - const QString scriptName = service.value(QStringLiteral("X-Plasma-MainScript")); - const QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, s_qmlPackageFolder + pluginName + QLatin1String("/contents/") + scriptName); + const QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, s_qmlPackageFolder + pluginName + QLatin1String("/contents/ui/main.qml")); if (file.isNull()) { qCDebug(AURORAE) << "Could not find script file for " << pluginName; // TODO: what to do in error case? diff --git a/src/scripting/scriptedeffect.cpp b/src/scripting/scriptedeffect.cpp index e768ddd88d..984f65d064 100644 --- a/src/scripting/scriptedeffect.cpp +++ b/src/scripting/scriptedeffect.cpp @@ -156,15 +156,10 @@ static KWin::FPx2 fpx2FromScriptValue(const QJSValue &value) ScriptedEffect *ScriptedEffect::create(const KPluginMetaData &effect) { const QString name = effect.pluginId(); - const QString scriptName = effect.value(QStringLiteral("X-Plasma-MainScript")); - if (scriptName.isEmpty()) { - qCDebug(KWIN_SCRIPTING) << "X-Plasma-MainScript not set"; - return nullptr; - } const QString scriptFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, - QLatin1String("kwin/effects/") + name + QLatin1String("/contents/") + scriptName); - if (scriptFile.isNull()) { - qCDebug(KWIN_SCRIPTING) << "Could not locate the effect script"; + QLatin1String("kwin/effects/") + name + QLatin1String("/contents/code/main.js")); + if (scriptFile.isEmpty()) { + qCDebug(KWIN_SCRIPTING) << "Could not locate effect script" << name; return nullptr; } @@ -830,8 +825,7 @@ void ScriptedEffect::setUniform(uint shaderId, const QString &name, const QJSVal m_engine->throwError(QStringLiteral("Failed to make OpenGL context current")); return; } - auto setColorUniform = [this, shader, name] (const QColor &color) - { + auto setColorUniform = [this, shader, name](const QColor &color) { if (!color.isValid()) { return; } diff --git a/src/scripting/scripting.cpp b/src/scripting/scripting.cpp index c66288e963..c9f2b96bae 100644 --- a/src/scripting/scripting.cpp +++ b/src/scripting/scripting.cpp @@ -721,9 +721,10 @@ LoadScriptList KWin::Scripting::queryScriptsToLoad() continue; } const QString pluginName = service.pluginId(); - const QString scriptName = service.value(QStringLiteral("X-Plasma-MainScript")); - const QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, scriptFolder + pluginName + QLatin1String("/contents/") + scriptName); - if (file.isNull()) { + // The file we want to load depends on the specified API. We could check if one or the other file exists, but that is more error prone and causes IO overhead + const QString relScriptPath = scriptFolder + pluginName + QLatin1String("/contents/") + (javaScript ? QLatin1String("code/main.js") : QLatin1String("ui/main.qml")); + const QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, relScriptPath); + if (file.isEmpty()) { qCDebug(KWIN_SCRIPTING) << "Could not find script file for " << pluginName; continue; }