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