diff --git a/src/core/generation.cpp b/src/core/generation.cpp index 5d24c5a..de5db17 100644 --- a/src/core/generation.cpp +++ b/src/core/generation.cpp @@ -27,6 +27,7 @@ EngineGeneration::EngineGeneration(QmlScanner scanner) , interceptNetFactory(this->scanner.qmldirIntercepts) { g_generations.insert(&this->engine, this); + this->engine.addUrlInterceptor(&this->urlInterceptor); this->engine.setNetworkAccessManagerFactory(&this->interceptNetFactory); this->engine.setIncubationController(&this->delayedIncubationController); } diff --git a/src/core/generation.hpp b/src/core/generation.hpp index 5c21a95..813190d 100644 --- a/src/core/generation.hpp +++ b/src/core/generation.hpp @@ -29,6 +29,7 @@ public: static EngineGeneration* findObjectGeneration(QObject* object); QmlScanner scanner; + QsUrlInterceptor urlInterceptor; QsInterceptNetworkAccessManagerFactory interceptNetFactory; QQmlEngine engine; ShellRoot* root = nullptr; diff --git a/src/core/qsintercept.cpp b/src/core/qsintercept.cpp index 35b9234..21b6abf 100644 --- a/src/core/qsintercept.cpp +++ b/src/core/qsintercept.cpp @@ -9,11 +9,26 @@ #include #include #include +#include #include #include +#include Q_LOGGING_CATEGORY(logQsIntercept, "quickshell.interceptor", QtWarningMsg); +QUrl QsUrlInterceptor::intercept(const QUrl& url, QQmlAbstractUrlInterceptor::DataType type) { + // Some types such as Image take into account where they are loading from, and force + // asynchronous loading over a network. qsintercept is considered to be over a network. + if (type == QQmlAbstractUrlInterceptor::DataType::UrlString && url.scheme() == "qsintercept") { + auto newUrl = url; + newUrl.setScheme("file"); + qCDebug(logQsIntercept) << "Rewrote intercept" << url << "to" << newUrl; + return newUrl; + } + + return url; +} + QsInterceptDataReply::QsInterceptDataReply(const QString& qmldir, QObject* parent) : QNetworkReply(parent) , content(qmldir.toUtf8()) { diff --git a/src/core/qsintercept.hpp b/src/core/qsintercept.hpp index 7e84da9..d51b78e 100644 --- a/src/core/qsintercept.hpp +++ b/src/core/qsintercept.hpp @@ -5,11 +5,17 @@ #include #include #include +#include #include #include Q_DECLARE_LOGGING_CATEGORY(logQsIntercept); +class QsUrlInterceptor: public QQmlAbstractUrlInterceptor { +public: + QUrl intercept(const QUrl& url, QQmlAbstractUrlInterceptor::DataType type) override; +}; + class QsInterceptDataReply: public QNetworkReply { Q_OBJECT;