From 7bfb4a93e28accf95b141f6c2ca7ca967fbfb381 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 19 Mar 2024 12:04:40 +0200 Subject: [PATCH] plugins/kpackage: Fix mainscript for declarative effects --- src/plugins/kpackage/effect/effect.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/plugins/kpackage/effect/effect.cpp b/src/plugins/kpackage/effect/effect.cpp index ff5064f55e..7b6c8c5a62 100644 --- a/src/plugins/kpackage/effect/effect.cpp +++ b/src/plugins/kpackage/effect/effect.cpp @@ -18,8 +18,8 @@ public: package->addDirectoryDefinition("code", QStringLiteral("code")); package->setMimeTypes("code", QStringList{QStringLiteral("text/plain")}); - package->addFileDefinition("mainscript", QStringLiteral("code/main.js")); - package->setRequired("mainscript", true); + package->addDirectoryDefinition("ui", QStringLiteral("ui")); + package->setMimeTypes("ui", QStringList{QStringLiteral("text/plain")}); package->addFileDefinition("config", QStringLiteral("config/main.xml")); package->setMimeTypes("config", QStringList{QStringLiteral("text/xml")}); @@ -27,6 +27,22 @@ public: package->addFileDefinition("configui", QStringLiteral("ui/config.ui")); package->setMimeTypes("configui", QStringList{QStringLiteral("text/xml")}); } + + void pathChanged(KPackage::Package *package) override + { + if (!package->metadata().isValid()) { + return; + } + + const QString api = package->metadata().value(QStringLiteral("X-Plasma-API")); + if (api == QStringLiteral("javascript")) { + package->addFileDefinition("mainscript", QStringLiteral("code/main.js")); + package->setRequired("mainscript", true); + } else if (api == QStringLiteral("declarativescript")) { + package->addFileDefinition("mainscript", QStringLiteral("ui/main.qml")); + package->setRequired("mainscript", true); + } + } }; K_PLUGIN_CLASS_WITH_JSON(EffectPackageStructure, "effect.json")