change to asset read
This commit is contained in:
parent
0b4b9c2ed6
commit
e6cff004d0
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "DoricDemoBridge.h"
|
#include "DoricDemoBridge.h"
|
||||||
#include "DoricPanel.h"
|
#include "DoricPanel.h"
|
||||||
|
#include "loader/DoricJSLoaderManager.h"
|
||||||
#include "utils/DoricDialogBridge.h"
|
#include "utils/DoricDialogBridge.h"
|
||||||
#include "utils/DoricDraggableBridge.h"
|
#include "utils/DoricDraggableBridge.h"
|
||||||
#include "utils/DoricImageBridge.h"
|
#include "utils/DoricImageBridge.h"
|
||||||
@ -36,9 +37,9 @@ DoricDemoBridge::DoricDemoBridge(QQmlApplicationEngine *engine, QObject *parent)
|
|||||||
context->setContextProperty("draggableBridge", draggableBridge);
|
context->setContextProperty("draggableBridge", draggableBridge);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricDemoBridge::navigate(QVariant route) {
|
void DoricDemoBridge::navigate(QVariant path, QVariant index) {
|
||||||
QString name;
|
QString name;
|
||||||
switch (route.toInt()) {
|
switch (index.toInt()) {
|
||||||
case 0:
|
case 0:
|
||||||
name = "ComponetDemo.js";
|
name = "ComponetDemo.js";
|
||||||
break;
|
break;
|
||||||
@ -109,7 +110,12 @@ void DoricDemoBridge::navigate(QVariant route) {
|
|||||||
name = "TextDemo.js";
|
name = "TextDemo.js";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
|
|
||||||
|
QString resourcePath = path.toString();
|
||||||
|
std::shared_ptr<DoricAsyncResult> asyncResult =
|
||||||
|
DoricJSLoaderManager::getInstance()->request(resourcePath + name);
|
||||||
|
|
||||||
|
QString script = asyncResult->getResult();
|
||||||
|
|
||||||
QQmlComponent component(mEngine);
|
QQmlComponent component(mEngine);
|
||||||
const QUrl url(QStringLiteral("qrc:/doric/qml/panel.qml"));
|
const QUrl url(QStringLiteral("qrc:/doric/qml/panel.qml"));
|
||||||
|
@ -11,7 +11,7 @@ public:
|
|||||||
QObject *parent = nullptr);
|
QObject *parent = nullptr);
|
||||||
|
|
||||||
Q_INVOKABLE
|
Q_INVOKABLE
|
||||||
void navigate(QVariant route);
|
void navigate(QVariant path, QVariant index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QQmlApplicationEngine *mEngine;
|
QQmlApplicationEngine *mEngine;
|
||||||
|
@ -148,7 +148,7 @@ ApplicationWindow {
|
|||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
demoBridge.navigate(index)
|
demoBridge.navigate("assets://src/", index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<qresource prefix="/fonts">
|
<qresource prefix="/fonts">
|
||||||
<file alias="assets_iconfont.ttf">./resources/assets_iconfont.ttf</file>
|
<file alias="assets_iconfont.ttf">./resources/assets_iconfont.ttf</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/doric/bundles">
|
<qresource prefix="src">
|
||||||
<file alias="ComponetDemo.js">../../../doric-demo/bundle/src/ComponetDemo.js</file>
|
<file alias="ComponetDemo.js">../../../doric-demo/bundle/src/ComponetDemo.js</file>
|
||||||
<file alias="Counter.js">../../../doric-demo/bundle/src/Counter.js</file>
|
<file alias="Counter.js">../../../doric-demo/bundle/src/Counter.js</file>
|
||||||
<file alias="DraggableDemo.js">../../../doric-demo/bundle/src/DraggableDemo.js</file>
|
<file alias="DraggableDemo.js">../../../doric-demo/bundle/src/DraggableDemo.js</file>
|
||||||
|
@ -10,7 +10,7 @@ private:
|
|||||||
QString result;
|
QString result;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::function<void()> resultCallback;
|
std::function<void()> resultCallback = [] {};
|
||||||
std::function<void()> exceptionCallback;
|
std::function<void()> exceptionCallback;
|
||||||
std::function<void()> finishCallback;
|
std::function<void()> finishCallback;
|
||||||
|
|
||||||
|
@ -12,8 +12,12 @@ std::shared_ptr<DoricAsyncResult> DoricAssetJSLoader::request(QString source) {
|
|||||||
QString protocol = "assets://";
|
QString protocol = "assets://";
|
||||||
QString assetPath = source.mid(protocol.length());
|
QString assetPath = source.mid(protocol.length());
|
||||||
|
|
||||||
|
QString script = DoricUtils::readAssetFile("/" + assetPath);
|
||||||
|
|
||||||
std::shared_ptr<DoricAsyncResult> asyncResult =
|
std::shared_ptr<DoricAsyncResult> asyncResult =
|
||||||
std::make_shared<DoricAsyncResult>();
|
std::make_shared<DoricAsyncResult>();
|
||||||
|
|
||||||
|
asyncResult->setResult(script);
|
||||||
|
|
||||||
return asyncResult;
|
return asyncResult;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,19 @@ public:
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QString readAssetFile(QString resourcePath) {
|
||||||
|
QResource resource(":" + resourcePath);
|
||||||
|
QFile *file = new QFile(resource.fileName());
|
||||||
|
file->open(QFile::ReadOnly | QFile::Text);
|
||||||
|
QTextStream in(file);
|
||||||
|
in.setCodec("UTF-8");
|
||||||
|
QString content = in.readAll();
|
||||||
|
file->close();
|
||||||
|
delete file;
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Base, typename T>
|
template <typename Base, typename T>
|
||||||
static inline bool instanceof (const T *) {
|
static inline bool instanceof (const T *) {
|
||||||
return std::is_base_of<Base, T>::value;
|
return std::is_base_of<Base, T>::value;
|
||||||
|
Reference in New Issue
Block a user