add async call on main
This commit is contained in:
parent
60218cd8dd
commit
b406460a8d
@ -59,6 +59,8 @@ DoricInterfaceDriver *DoricContext::getDriver() {
|
|||||||
return driver;
|
return driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DoricRootNode *DoricContext::getRootNode() { return mRootNode; }
|
||||||
|
|
||||||
QObject *DoricContext::obtainPlugin(QString name) {
|
QObject *DoricContext::obtainPlugin(QString name) {
|
||||||
if (mPluginMap.keys().contains(name)) {
|
if (mPluginMap.keys().contains(name)) {
|
||||||
return mPluginMap.value(name);
|
return mPluginMap.value(name);
|
||||||
|
@ -30,6 +30,8 @@ public:
|
|||||||
|
|
||||||
DoricInterfaceDriver *getDriver();
|
DoricInterfaceDriver *getDriver();
|
||||||
|
|
||||||
|
DoricRootNode *getRootNode();
|
||||||
|
|
||||||
QObject *obtainPlugin(QString name);
|
QObject *obtainPlugin(QString name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ DoricAsyncResult *DoricNativeDriver::asyncCall(std::function<void()> lambda,
|
|||||||
DoricThreadMode mode) {
|
DoricThreadMode mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case UI:
|
case UI:
|
||||||
|
DoricAsyncCall::ensureRunInMain(lambda);
|
||||||
break;
|
break;
|
||||||
case JS:
|
case JS:
|
||||||
DoricAsyncCall::ensureRunInThreadPool(&jsEngine.mJSThreadPool, lambda);
|
DoricAsyncCall::ensureRunInThreadPool(&jsEngine.mJSThreadPool, lambda);
|
||||||
|
@ -13,6 +13,21 @@ public:
|
|||||||
QFuture<std::function<void()>::result_type> future =
|
QFuture<std::function<void()>::result_type> future =
|
||||||
QtConcurrent::run(threadPool, lambda);
|
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
|
#endif // ASYNC_CALL_H
|
||||||
|
@ -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.js";
|
QString name = "Snake.es5.js";
|
||||||
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
|
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
|
||||||
|
|
||||||
DoricPanel panel;
|
DoricPanel panel;
|
||||||
|
@ -4,4 +4,10 @@
|
|||||||
|
|
||||||
void DoricShaderPlugin::render(QJSValue jsValue, QString callbackId) {
|
void DoricShaderPlugin::render(QJSValue jsValue, QString callbackId) {
|
||||||
qDebug() << getContext();
|
qDebug() << getContext();
|
||||||
|
getContext()->getDriver()->asyncCall(
|
||||||
|
[this, jsValue] {
|
||||||
|
QString viewId = jsValue.property("id").toString();
|
||||||
|
getContext()->getDriver();
|
||||||
|
},
|
||||||
|
DoricThreadMode::UI);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "DoricConstant.h"
|
#include "DoricConstant.h"
|
||||||
|
|
||||||
const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.js";
|
const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.es5.js";
|
||||||
const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.js";
|
const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.es5.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";
|
||||||
|
Reference in New Issue
Block a user