core/intercept: do not intercept non qml files

Avoids forcing Images to lazy load which causes unexpected flashes.
This commit is contained in:
outfoxxed 2024-03-19 21:30:46 -07:00
parent 518977932d
commit 9f38908bdf
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 23 additions and 0 deletions

View file

@ -27,6 +27,7 @@ EngineGeneration::EngineGeneration(QmlScanner scanner)
, interceptNetFactory(this->scanner.qmldirIntercepts) { , interceptNetFactory(this->scanner.qmldirIntercepts) {
g_generations.insert(&this->engine, this); g_generations.insert(&this->engine, this);
this->engine.addUrlInterceptor(&this->urlInterceptor);
this->engine.setNetworkAccessManagerFactory(&this->interceptNetFactory); this->engine.setNetworkAccessManagerFactory(&this->interceptNetFactory);
this->engine.setIncubationController(&this->delayedIncubationController); this->engine.setIncubationController(&this->delayedIncubationController);
} }

View file

@ -29,6 +29,7 @@ public:
static EngineGeneration* findObjectGeneration(QObject* object); static EngineGeneration* findObjectGeneration(QObject* object);
QmlScanner scanner; QmlScanner scanner;
QsUrlInterceptor urlInterceptor;
QsInterceptNetworkAccessManagerFactory interceptNetFactory; QsInterceptNetworkAccessManagerFactory interceptNetFactory;
QQmlEngine engine; QQmlEngine engine;
ShellRoot* root = nullptr; ShellRoot* root = nullptr;

View file

@ -9,11 +9,26 @@
#include <qnetworkaccessmanager.h> #include <qnetworkaccessmanager.h>
#include <qnetworkrequest.h> #include <qnetworkrequest.h>
#include <qobject.h> #include <qobject.h>
#include <qqmlabstracturlinterceptor.h>
#include <qstring.h> #include <qstring.h>
#include <qtypes.h> #include <qtypes.h>
#include <qurl.h>
Q_LOGGING_CATEGORY(logQsIntercept, "quickshell.interceptor", QtWarningMsg); 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) QsInterceptDataReply::QsInterceptDataReply(const QString& qmldir, QObject* parent)
: QNetworkReply(parent) : QNetworkReply(parent)
, content(qmldir.toUtf8()) { , content(qmldir.toUtf8()) {

View file

@ -5,11 +5,17 @@
#include <qnetworkaccessmanager.h> #include <qnetworkaccessmanager.h>
#include <qnetworkreply.h> #include <qnetworkreply.h>
#include <qnetworkrequest.h> #include <qnetworkrequest.h>
#include <qqmlabstracturlinterceptor.h>
#include <qqmlnetworkaccessmanagerfactory.h> #include <qqmlnetworkaccessmanagerfactory.h>
#include <qurl.h> #include <qurl.h>
Q_DECLARE_LOGGING_CATEGORY(logQsIntercept); Q_DECLARE_LOGGING_CATEGORY(logQsIntercept);
class QsUrlInterceptor: public QQmlAbstractUrlInterceptor {
public:
QUrl intercept(const QUrl& url, QQmlAbstractUrlInterceptor::DataType type) override;
};
class QsInterceptDataReply: public QNetworkReply { class QsInterceptDataReply: public QNetworkReply {
Q_OBJECT; Q_OBJECT;