add asset js loader & export doric classes

This commit is contained in:
王劲鹏 2021-06-10 10:31:23 +08:00 committed by osborn
parent 928a4ab038
commit 0b4b9c2ed6
20 changed files with 92 additions and 19 deletions

View File

@ -1,9 +1,11 @@
#ifndef DORIC_H
#define DORIC_H
#include "DoricExport.h"
#include "DoricLibrary.h"
class Doric {
class DORIC_EXPORT Doric {
public:
static void registerLibrary(DoricLibrary *doricLibrary) {
DoricRegistry::getInstance()->registerLibrary(doricLibrary);

View File

@ -5,11 +5,13 @@
#include <QString>
#include <QVariant>
#include "DoricExport.h"
#include "DoricRegistry.h"
#include "async/DoricAsyncResult.h"
#include "utils/DoricThreadMode.h"
class DoricInterfaceDriver {
class DORIC_EXPORT DoricInterfaceDriver {
public:
virtual std::shared_ptr<DoricAsyncResult>
invokeContextEntityMethod(QString contextId, QString method,

View File

@ -1,9 +1,11 @@
#ifndef DORICLIBRARY_H
#define DORICLIBRARY_H
#include "DoricExport.h"
#include "DoricRegistry.h"
class DoricLibrary {
class DORIC_EXPORT DoricLibrary {
public:
virtual void load(DoricRegistry *registry) = 0;
};

View File

@ -5,9 +5,11 @@
#include <QThreadPool>
#include <QtConcurrent/QtConcurrent>
#include "DoricExport.h"
#include "DoricAsyncResult.h"
class DoricAsyncCall {
class DORIC_EXPORT DoricAsyncCall {
public:
template <typename Function>

View File

@ -36,6 +36,7 @@ SOURCES += \
engine/native/NativeExecutor.cpp \
engine/v8/JSValueHelper.cpp \
engine/v8/V8Executor.cpp \
loader/DoricAssetJSLoader.cpp \
loader/DoricJSLoaderManager.cpp \
plugin/DoricModalPlugin.cpp \
plugin/DoricNavigatorPlugin.cpp \
@ -125,6 +126,7 @@ HEADERS += \
engine/native/NativeExecutor.h \
engine/v8/JSValueHelper.h \
engine/v8/V8Executor.h \
loader/DoricAssetJSLoader.h \
loader/DoricInterfaceLoader.h \
loader/DoricJSLoaderManager.h \
plugin/DoricModalPlugin.h \

View File

@ -4,7 +4,9 @@
#include <QString>
#include <QVariant>
class DoricInterfaceJSE {
#include "DoricExport.h"
class DORIC_EXPORT DoricInterfaceJSE {
public:
virtual QString loadJS(QString script, QString source) = 0;

View File

@ -6,7 +6,9 @@
#include "DoricContext.h"
#include "utils/DoricConstant.h"
class DoricPromise {
#include "DoricExport.h"
class DORIC_EXPORT DoricPromise {
public:
static void resolve(DoricContext *context, QString callbackId,
QVariantList args) {

View File

@ -3,7 +3,9 @@
#include <QJSEngine>
class NativeExecutor {
#include "DoricExport.h"
class DORIC_EXPORT NativeExecutor {
private:
QJSEngine *mJSEngine;

View File

@ -8,10 +8,12 @@
#include <QObject>
#include <QString>
#include "DoricExport.h"
static QMap<QString, QPair<QObject *, QString>> *map =
new QMap<QString, QPair<QObject *, QString>>();
class V8Executor {
class DORIC_EXPORT V8Executor {
private:
std::unique_ptr<v8::Platform> platform;

View File

@ -0,0 +1,19 @@
#include "DoricAssetJSLoader.h"
#include "utils/DoricUtils.h"
DoricAssetJSLoader::DoricAssetJSLoader() {}
bool DoricAssetJSLoader::filter(QString source) {
return source.startsWith("assets");
}
std::shared_ptr<DoricAsyncResult> DoricAssetJSLoader::request(QString source) {
QString protocol = "assets://";
QString assetPath = source.mid(protocol.length());
std::shared_ptr<DoricAsyncResult> asyncResult =
std::make_shared<DoricAsyncResult>();
return asyncResult;
}

View File

@ -0,0 +1,17 @@
#ifndef DORICASSETJSLOADER_H
#define DORICASSETJSLOADER_H
#include "DoricExport.h"
#include "DoricInterfaceLoader.h"
class DORIC_EXPORT DoricAssetJSLoader : public DoricInterfaceLoader {
public:
DoricAssetJSLoader();
virtual bool filter(QString source) override;
virtual std::shared_ptr<DoricAsyncResult> request(QString source) override;
};
#endif // DORICASSETJSLOADER_H

View File

@ -1,11 +1,13 @@
#ifndef DORICINTERFACELOADER_H
#define DORICINTERFACELOADER_H
#include "async/DoricAsyncResult.h"
#include <QString>
class DoricInterfaceLoader {
#include "DoricExport.h"
#include "async/DoricAsyncResult.h"
class DORIC_EXPORT DoricInterfaceLoader {
public:
virtual bool filter(QString source) = 0;

View File

@ -1,7 +1,10 @@
#include "DoricJSLoaderManager.h"
#include "DoricAssetJSLoader.h"
DoricJSLoaderManager::DoricJSLoaderManager() {
qDebug() << "DoricJSLoaderManager constructor";
addJSLoader(new DoricAssetJSLoader());
}
void DoricJSLoaderManager::addJSLoader(DoricInterfaceLoader *jsLoader) {

View File

@ -3,9 +3,11 @@
#include <QDebug>
#include "DoricExport.h"
#include "DoricInterfaceLoader.h"
class DoricJSLoaderManager {
class DORIC_EXPORT DoricJSLoaderManager {
private:
static DoricJSLoaderManager *local_instance;

View File

@ -1,9 +1,11 @@
#ifndef DORICNATIVEPLUGIN_H
#define DORICNATIVEPLUGIN_H
#include "DoricExport.h"
#include "../utils/DoricContextHolder.h"
class DoricNativePlugin : public DoricContextHolder {
class DORIC_EXPORT DoricNativePlugin : public DoricContextHolder {
public:
using DoricContextHolder::DoricContextHolder;
};

View File

@ -3,7 +3,9 @@
#include <QDebug>
class DoricSingleton {
#include "DoricExport.h"
class DORIC_EXPORT DoricSingleton {
private:
static DoricSingleton *local_instance;
DoricSingleton() { qDebug() << "constructor"; }

View File

@ -3,7 +3,9 @@
#include <QDebug>
class DoricGlobalBroadcast {
#include "DoricExport.h"
class DORIC_EXPORT DoricGlobalBroadcast {
private:
static DoricGlobalBroadcast *local_instance;
DoricGlobalBroadcast() { qDebug() << "DoricGlobalBroadcast constructor"; }

View File

@ -9,7 +9,9 @@
#include <QNetworkRequest>
#include <QThread>
class InnerTask : public QObject {
#include "DoricExport.h"
class DORIC_EXPORT InnerTask : public QObject {
Q_OBJECT
private:
QNetworkRequest httpRequest;
@ -63,7 +65,7 @@ signals:
void response(int code, QList<QByteArray> headers, QByteArray data);
};
class DoricNetworkService : public QObject {
class DORIC_EXPORT DoricNetworkService : public QObject {
Q_OBJECT
private:
QThread thread;

View File

@ -5,7 +5,9 @@
#include <QHash>
#include <QMetaObject>
class DoricObjectFactory {
#include "DoricExport.h"
class DORIC_EXPORT DoricObjectFactory {
public:
template <typename T> static void registerClass(QString name) {
constructors().insert(name, &constructorHelper<T>);

View File

@ -7,7 +7,9 @@
#include <QString>
#include <QTextStream>
class DoricUtils {
#include "DoricExport.h"
class DORIC_EXPORT DoricUtils {
public:
static QString readAssetFile(QString preffix, QString assetName) {
QResource resource(":" + preffix + "/" + assetName);