Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libinputactions/scripting/ScriptingEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Promise;

/**
* Lazily initializated.
*
* Q_PROPERTIES exposed to JavaScript of non-primitive types (with the exception of QObject *) must be of type QJSValue to prevent object reuse.
*/
class ScriptingEngine : public QObject
{
Expand Down
7 changes: 6 additions & 1 deletion src/libinputactions/variables/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

#include "Variable.h"
#include <QJSEngine>
#include <libinputactions/scripting/ScriptingEngine.h>

namespace InputActions
{
Expand All @@ -39,4 +39,9 @@ const QMetaType &Variable::type() const
return m_type;
}

QJSValue Variable::scriptValue() const
{
return g_scriptingEngine->ensureEngine().toScriptValue(value());
}

}
5 changes: 4 additions & 1 deletion src/libinputactions/variables/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include "VariableOperations.h"
#include <QJSValue>
#include <QObject>
#include <QString>

Expand All @@ -28,7 +29,7 @@ namespace InputActions
class Variable : public QObject
{
Q_OBJECT
Q_PROPERTY(QVariant value READ value)
Q_PROPERTY(QJSValue value READ scriptValue)

public:
Variable(QMetaType type);
Expand Down Expand Up @@ -57,6 +58,8 @@ class Variable : public QObject
void setHidden(bool value) { m_hidden = value; }

private:
QJSValue scriptValue() const;

QMetaType m_type;
std::variant<bool, QString> m_value;
std::unique_ptr<VariableOperationsBase> m_operations;
Expand Down