forked from quickshell/quickshell
core/intercept: do not intercept non qml files
Avoids forcing Images to lazy load which causes unexpected flashes.
This commit is contained in:
parent
518977932d
commit
9f38908bdf
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
static EngineGeneration* findObjectGeneration(QObject* object);
|
||||
|
||||
QmlScanner scanner;
|
||||
QsUrlInterceptor urlInterceptor;
|
||||
QsInterceptNetworkAccessManagerFactory interceptNetFactory;
|
||||
QQmlEngine engine;
|
||||
ShellRoot* root = nullptr;
|
||||
|
|
|
@ -9,11 +9,26 @@
|
|||
#include <qnetworkaccessmanager.h>
|
||||
#include <qnetworkrequest.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmlabstracturlinterceptor.h>
|
||||
#include <qstring.h>
|
||||
#include <qtypes.h>
|
||||
#include <qurl.h>
|
||||
|
||||
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()) {
|
||||
|
|
|
@ -5,11 +5,17 @@
|
|||
#include <qnetworkaccessmanager.h>
|
||||
#include <qnetworkreply.h>
|
||||
#include <qnetworkrequest.h>
|
||||
#include <qqmlabstracturlinterceptor.h>
|
||||
#include <qqmlnetworkaccessmanagerfactory.h>
|
||||
#include <qurl.h>
|
||||
|
||||
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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue