* @brief Installs apiCall() / apiCallList() into a QJSEngine, reusing the bridge if attached. */
| 746 | * @brief Installs apiCall() / apiCallList() into a QJSEngine, reusing the bridge if attached. |
| 747 | */ |
| 748 | void DataModel::ScriptApiCall::installJS(QJSEngine* js, int sourceId) |
| 749 | { |
| 750 | Q_ASSERT(js); |
| 751 | |
| 752 | auto global = js->globalObject(); |
| 753 | auto existingProp = global.property(QStringLiteral("__ss_bridge")); |
| 754 | if (existingProp.isQObject() |
| 755 | && qobject_cast<DataModel::ScriptApiCallBridge*>(existingProp.toQObject())) |
| 756 | return; |
| 757 | |
| 758 | auto* bridge = new DataModel::ScriptApiCallBridge(sourceId, js); |
| 759 | auto bridgeVal = js->newQObject(bridge); |
| 760 | global.setProperty(QStringLiteral("__ss_bridge"), bridgeVal); |
| 761 | |
| 762 | static const QByteArray sdk = loadSdk(QStringLiteral(":/api/SerialStudio.js")); |
| 763 | if (!sdk.isEmpty()) |
| 764 | js->evaluate(QString::fromUtf8(sdk)); |
| 765 | } |
| 766 | |
| 767 | /** |
| 768 | * @brief Installs the convenience host bridges (no apiCall bridge, no SDK eval). |