add async call on main
This commit is contained in:
parent
60218cd8dd
commit
b406460a8d
@ -59,6 +59,8 @@ DoricInterfaceDriver *DoricContext::getDriver() {
|
||||
return driver;
|
||||
}
|
||||
|
||||
DoricRootNode *DoricContext::getRootNode() { return mRootNode; }
|
||||
|
||||
QObject *DoricContext::obtainPlugin(QString name) {
|
||||
if (mPluginMap.keys().contains(name)) {
|
||||
return mPluginMap.value(name);
|
||||
|
@ -30,6 +30,8 @@ public:
|
||||
|
||||
DoricInterfaceDriver *getDriver();
|
||||
|
||||
DoricRootNode *getRootNode();
|
||||
|
||||
QObject *obtainPlugin(QString name);
|
||||
};
|
||||
|
||||
|
@ -23,6 +23,7 @@ DoricAsyncResult *DoricNativeDriver::asyncCall(std::function<void()> lambda,
|
||||
DoricThreadMode mode) {
|
||||
switch (mode) {
|
||||
case UI:
|
||||
DoricAsyncCall::ensureRunInMain(lambda);
|
||||
break;
|
||||
case JS:
|
||||
DoricAsyncCall::ensureRunInThreadPool(&jsEngine.mJSThreadPool, lambda);
|
||||
|
@ -13,6 +13,21 @@ public:
|
||||
QFuture<std::function<void()>::result_type> future =
|
||||
QtConcurrent::run(threadPool, lambda);
|
||||
}
|
||||
|
||||
template <typename Function>
|
||||
static void ensureRunInMain(Function &&function) {
|
||||
struct Event : public QEvent {
|
||||
using DecayedFunction = typename std::decay<Function>::type;
|
||||
DecayedFunction decayedFunction;
|
||||
Event(DecayedFunction &&decayedFunction)
|
||||
: QEvent(QEvent::None), decayedFunction(std::move(decayedFunction)) {}
|
||||
Event(const DecayedFunction &decayedFunction)
|
||||
: QEvent(QEvent::None), decayedFunction(decayedFunction) {}
|
||||
~Event() { decayedFunction(); }
|
||||
};
|
||||
QCoreApplication::postEvent(qApp,
|
||||
new Event(std::forward<Function>(function)));
|
||||
}
|
||||
};
|
||||
|
||||
#endif // ASYNC_CALL_H
|
||||
|
@ -9,7 +9,7 @@ DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {}
|
||||
void DoricDemoBridge::navigate(QVariant route) {
|
||||
switch (route.toInt()) {
|
||||
case 0:
|
||||
QString name = "Snake.js";
|
||||
QString name = "Snake.es5.js";
|
||||
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
|
||||
|
||||
DoricPanel panel;
|
||||
|
@ -4,4 +4,10 @@
|
||||
|
||||
void DoricShaderPlugin::render(QJSValue jsValue, QString callbackId) {
|
||||
qDebug() << getContext();
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, jsValue] {
|
||||
QString viewId = jsValue.property("id").toString();
|
||||
getContext()->getDriver();
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "DoricConstant.h"
|
||||
|
||||
const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.js";
|
||||
const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.js";
|
||||
const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.es5.js";
|
||||
const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.es5.js";
|
||||
const QString DoricConstant::DORIC_MODULE_LIB = "doric";
|
||||
|
||||
const QString DoricConstant::INJECT_ENVIRONMENT = "Environment";
|
||||
|
Reference in New Issue
Block a user