fix json value crash & timer not work

This commit is contained in:
王劲鹏 2021-04-06 17:58:23 +08:00 committed by osborn
parent fc0af6e992
commit c01bd1e98c
5 changed files with 36 additions and 22 deletions

View File

@ -11,8 +11,6 @@ DoricBridgeExtension::DoricBridgeExtension(QObject *parent) : QObject(parent) {}
void DoricBridgeExtension::callNative(QString contextId, QString module,
QString methodName, QString callbackId,
QString argument) {
QJsonDocument document = QJsonDocument::fromJson(argument.toUtf8());
QJsonObject jsValue = document.object();
DoricContext *context =
DoricContextManager::getInstance()->getContext(contextId);
bool classRegistered =
@ -21,7 +19,7 @@ void DoricBridgeExtension::callNative(QString contextId, QString module,
QObject *plugin = context->obtainPlugin(module);
QMetaObject::invokeMethod(plugin, methodName.toUtf8(), Qt::DirectConnection,
QGenericReturnArgument(),
Q_ARG(QJsonObject *, &jsValue),
Q_ARG(QString, argument),
Q_ARG(QString, callbackId));
}
qDebug() << "contextId: " + contextId << "module: " + module

View File

@ -1,3 +1,4 @@
#include <QCoreApplication>
#include <QTimer>
#include "../utils/DoricConstant.h"
@ -5,22 +6,29 @@
Q_INVOKABLE void DoricTimerExtension::setTimer(long timerId, int time,
bool repeat) {
QTimer *timer = new QTimer(this);
timer->setSingleShot(!repeat);
connect(timer, &QTimer::timeout, this, [=]() {
if (deletedTimerIds->contains(timerId)) {
deletedTimerIds->remove(timerId);
delete timer;
} else {
this->method(timerId);
if (!repeat) {
connect(this, &DoricTimerExtension::startTimer, qApp, [=]() {
QTimer *timer = new QTimer();
timer->setSingleShot(!repeat);
connect(timer, &QTimer::timeout, [=]() {
if (deletedTimerIds->contains(timerId)) {
deletedTimerIds->remove(timerId);
delete timer;
timer->deleteLater();
} else {
this->method(timerId);
if (!repeat) {
deletedTimerIds->remove(timerId);
timer->deleteLater();
}
}
}
});
timer->start(time);
});
timer->start(time);
emit startTimer();
}
Q_INVOKABLE void DoricTimerExtension::clearTimer(long timerId) {

View File

@ -21,5 +21,8 @@ public:
Q_INVOKABLE void setTimer(long timerId, int time, bool repeat);
Q_INVOKABLE void clearTimer(long timerId);
signals:
void startTimer();
};
#endif // NATIVETIMER_H

View File

@ -1,24 +1,29 @@
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include "../shader/DoricRootNode.h"
#include "DoricShaderPlugin.h"
void DoricShaderPlugin::render(QJsonObject *jsValue, QString callbackId) {
void DoricShaderPlugin::render(QString jsValueString, QString callbackId) {
getContext()->getDriver()->asyncCall(
[this, jsValue] {
[this, jsValueString] {
try {
QString viewId = jsValue->value("id").toString();
QJsonDocument document =
QJsonDocument::fromJson(jsValueString.toUtf8());
QJsonValue jsValue = document.object();
QString viewId = jsValue["id"].toString();
DoricRootNode *rootNode = getContext()->getRootNode();
if (rootNode->getId().isEmpty() &&
jsValue->value("type").toString() == "Root") {
jsValue["type"].toString() == "Root") {
rootNode->setId(viewId);
rootNode->blend(jsValue->value("props"));
rootNode->blend(jsValue["props"]);
} else {
DoricViewNode *viewNode = getContext()->targetViewNode(viewId);
if (viewNode != nullptr) {
viewNode->blend(jsValue->value("props"));
viewNode->blend(jsValue["props"]);
}
}
} catch (...) {

View File

@ -11,7 +11,7 @@ class DoricShaderPlugin : public DoricNativePlugin {
public:
using DoricNativePlugin::DoricNativePlugin;
Q_INVOKABLE void render(QJsonObject *jsValue, QString callbackId);
Q_INVOKABLE void render(QString jsValueString, QString callbackId);
};
#endif // SHADERPLUGIN_H