From 3aea522de25dcfe250c8052c3df9b54d2f6b2e1f Mon Sep 17 00:00:00 2001 From: taj-ny <79316397+taj-ny@users.noreply.github.com> Date: Fri, 31 Jul 2026 20:54:29 +0200 Subject: [PATCH] scripting: add VariableRegistryWrapper::variable --- .../scripting/modules/core/VariableRegistryWrapper.cpp | 6 ++++++ .../scripting/modules/core/VariableRegistryWrapper.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/libinputactions/scripting/modules/core/VariableRegistryWrapper.cpp b/src/libinputactions/scripting/modules/core/VariableRegistryWrapper.cpp index f928f4d..740c6bd 100644 --- a/src/libinputactions/scripting/modules/core/VariableRegistryWrapper.cpp +++ b/src/libinputactions/scripting/modules/core/VariableRegistryWrapper.cpp @@ -57,6 +57,12 @@ VariableWrapper *VariableRegistryWrapper::get(const QString &name) const return new VariableWrapper(*variable, m_engine); } +VariableWrapper *VariableRegistryWrapper::variable(const QString &name) const +{ + auto *variable = m_variableRegistry.variable(name); + return variable ? new VariableWrapper(*variable, m_engine) : nullptr; +} + VariableWrapper *VariableRegistryWrapper::registerComputedVariable(const QString &name, VariableType type, QJSValue getter) const { if (!m_registrationAllowed) { diff --git a/src/libinputactions/scripting/modules/core/VariableRegistryWrapper.h b/src/libinputactions/scripting/modules/core/VariableRegistryWrapper.h index 0c505fa..88466b8 100644 --- a/src/libinputactions/scripting/modules/core/VariableRegistryWrapper.h +++ b/src/libinputactions/scripting/modules/core/VariableRegistryWrapper.h @@ -39,6 +39,10 @@ class VariableRegistryWrapper : public QObject Q_INVOKABLE bool contains(const QString &name) const; Q_INVOKABLE VariableWrapper *get(const QString &name) const; + /** + * Deprecated, kept for backwards compatibility. Returns null instead of throwing when variable doesn't exist. + */ + Q_INVOKABLE VariableWrapper *variable(const QString &name) const; Q_INVOKABLE VariableWrapper *registerComputedVariable(const QString &name, VariableType type, QJSValue getter) const; Q_INVOKABLE StoredVariableWrapper *registerStoredVariable(const QString &name, VariableType type) const;