add view node

This commit is contained in:
王劲鹏 2021-02-08 11:37:51 +08:00 committed by osborn
parent ceb08bfa1d
commit ed7d186510
10 changed files with 37 additions and 8 deletions

View File

@ -16,7 +16,7 @@ public:
virtual void invokeDoricMethod(QString method, QVariantList args) = 0; virtual void invokeDoricMethod(QString method, QVariantList args) = 0;
virtual DoricAsyncResult *asyncCall(QRunnable *runnable, virtual DoricAsyncResult *asyncCall(std::function<void()> lambda,
DoricThreadMode mode) = 0; DoricThreadMode mode) = 0;
virtual void createContext(QString contextId, QString script, virtual void createContext(QString contextId, QString script,

View File

@ -19,8 +19,15 @@ void DoricNativeDriver::invokeDoricMethod(QString method, QVariantList args) {
}); });
} }
DoricAsyncResult *DoricNativeDriver::asyncCall(QRunnable *runnable, DoricAsyncResult *DoricNativeDriver::asyncCall(std::function<void()> lambda,
DoricThreadMode mode) { DoricThreadMode mode) {
switch (mode) {
case UI:
break;
case JS:
DoricAsyncCall::ensureRunInThreadPool(&jsEngine.mJSThreadPool, lambda);
break;
}
return NULL; return NULL;
} }

View File

@ -26,7 +26,8 @@ public:
void invokeDoricMethod(QString method, QVariantList args) override; void invokeDoricMethod(QString method, QVariantList args) override;
DoricAsyncResult * asyncCall(QRunnable *runnable, DoricThreadMode mode) override; DoricAsyncResult *asyncCall(std::function<void()> lambda,
DoricThreadMode mode) override;
void createContext(QString contextId, QString script, void createContext(QString contextId, QString script,
QString source) override; QString source) override;

View File

@ -1,6 +1,7 @@
#ifndef ASYNC_CALL_H #ifndef ASYNC_CALL_H
#define ASYNC_CALL_H #define ASYNC_CALL_H
#include <QFuture>
#include <QThreadPool> #include <QThreadPool>
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
@ -9,7 +10,8 @@ class DoricAsyncCall {
public: public:
static void ensureRunInThreadPool(QThreadPool *threadPool, static void ensureRunInThreadPool(QThreadPool *threadPool,
std::function<void()> lambda) { std::function<void()> lambda) {
QtConcurrent::run(threadPool, lambda); QFuture<std::function<void()>::result_type> future =
QtConcurrent::run(threadPool, lambda);
} }
}; };

View File

@ -9,7 +9,7 @@ DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {}
void DoricDemoBridge::navigate(QVariant route) { void DoricDemoBridge::navigate(QVariant route) {
switch (route.toInt()) { switch (route.toInt()) {
case 0: case 0:
QString name = "Snake.es5.js"; QString name = "Snake.js";
QString script = DoricUtils::readAssetFile("/doric/bundles", name); QString script = DoricUtils::readAssetFile("/doric/bundles", name);
DoricPanel panel; DoricPanel panel;

View File

@ -32,6 +32,7 @@ SOURCES += \
main.cpp \ main.cpp \
plugin/DoricShaderPlugin.cpp \ plugin/DoricShaderPlugin.cpp \
shader/DoricRootNode.cpp \ shader/DoricRootNode.cpp \
shader/DoricViewNode.cpp \
utils/DoricConstant.cpp \ utils/DoricConstant.cpp \
utils/DoricContextHolder.cpp utils/DoricContextHolder.cpp
@ -71,6 +72,7 @@ HEADERS += \
plugin/DoricNativePlugin.h \ plugin/DoricNativePlugin.h \
plugin/DoricShaderPlugin.h \ plugin/DoricShaderPlugin.h \
shader/DoricRootNode.h \ shader/DoricRootNode.h \
shader/DoricViewNode.h \
template/DoricSingleton.h \ template/DoricSingleton.h \
utils/DoricConstant.h \ utils/DoricConstant.h \
utils/DoricContextHolder.h \ utils/DoricContextHolder.h \

View File

@ -57,9 +57,15 @@ QJSValue DoricNativeJSE::invokeObject(QString objectName, QString functionName,
} }
QJSValue result = function.call(args); QJSValue result = function.call(args);
if (result.isError()) if (result.isError()) {
qDebug() << "Uncaught exception at line" qDebug() << "Uncaught exception at line"
<< result.property("lineNumber").toInt() << ":" << result.property("lineNumber").toInt() << ":"
<< result.toString(); << result.toString();
QStringList stacktraces = result.property("stack").toString().split("\n");
qDebug() << "++++++++++++++++++++++++";
foreach (QString stacktrace, stacktraces) { qDebug() << stacktrace; }
qDebug() << "------------------------";
}
return result; return result;
} }

View File

@ -0,0 +1 @@
#include "DoricViewNode.h"

View File

@ -0,0 +1,10 @@
#ifndef DORICVIEWNODE_H
#define DORICVIEWNODE_H
#include "../utils/DoricContextHolder.h"
class DoricViewNode : public DoricContextHolder {
public:
using DoricContextHolder::DoricContextHolder;
};
#endif // DORICVIEWNODE_H

View File

@ -1,7 +1,7 @@
#include "DoricConstant.h" #include "DoricConstant.h"
const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.es5.js"; const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.js";
const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.es5.js"; const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.js";
const QString DoricConstant::DORIC_MODULE_LIB = "doric"; const QString DoricConstant::DORIC_MODULE_LIB = "doric";
const QString DoricConstant::INJECT_ENVIRONMENT = "Environment"; const QString DoricConstant::INJECT_ENVIRONMENT = "Environment";