chore(plasmaapi): replace root js object with qml context

The script is actually loaded via QML and therefore it uses context
properties instead of the global object. If the script were loaded as a
javascript - it would use the global object.
This commit is contained in:
Mikhail Zolotukhin 2022-02-15 19:56:31 +03:00
parent b43ca58b33
commit d58cfd240c
2 changed files with 7 additions and 4 deletions

View File

@ -3,6 +3,8 @@
#include "workspace.hpp"
#include <QQmlContext>
#include "logger.hpp"
#include "plasma-api/client.hpp"
#include "plasma-api/plasma-api.hpp"
@ -13,7 +15,7 @@ namespace PlasmaApi
Workspace::Workspace(QQmlEngine *engine)
: QObject()
, m_engine(engine)
, m_kwinImpl(engine->globalObject().property("workspace").toQObject())
, m_kwinImpl(m_engine->rootContext()->contextProperty(QStringLiteral("workspace")).value<QObject *>())
{
wrapSignals();
}

View File

@ -4,6 +4,7 @@
#include <doctest/doctest.h>
#include <QObject>
#include <QQmlContext>
#include <QQmlEngine>
#include <QSignalSpy>
@ -49,7 +50,7 @@ TEST_CASE("Workspace Properties Read")
auto mockWorkspace = MockWorkspaceJS();
mockWorkspace.setCurrentDesktop(42);
engine.globalObject().setProperty(QStringLiteral("workspace"), engine.newQObject(&mockWorkspace));
engine.rootContext()->setContextProperty(QStringLiteral("workspace"), &mockWorkspace);
auto plasmaApi = ::PlasmaApi::PlasmaApi(&engine);
auto workspace = plasmaApi.workspace();
@ -66,7 +67,7 @@ TEST_CASE("Workspace Properties Write")
auto engine = QQmlEngine();
auto mockWorkspace = MockWorkspaceJS();
engine.globalObject().setProperty(QStringLiteral("workspace"), engine.newQObject(&mockWorkspace));
engine.rootContext()->setContextProperty(QStringLiteral("workspace"), &mockWorkspace);
auto plasmaApi = ::PlasmaApi::PlasmaApi(&engine);
auto workspace = plasmaApi.workspace();
@ -85,7 +86,7 @@ TEST_CASE("Workspace Properties Signals")
auto engine = QQmlEngine();
auto mockWorkspace = MockWorkspaceJS();
engine.globalObject().setProperty(QStringLiteral("workspace"), engine.newQObject(&mockWorkspace));
engine.rootContext()->setContextProperty(QStringLiteral("workspace"), &mockWorkspace);
auto plasmaApi = ::PlasmaApi::PlasmaApi(&engine);
auto workspace = plasmaApi.workspace();