1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Make Qt 6 builds use a custom profile instead of the QtWebEngine defaultProfile. In Qt 6, defaultProfile is off-the-record which means every session would behave like private/incognito mode.

This commit is contained in:
Tiernan Hubble 2023-04-23 17:14:58 -06:00 committed by Juraj Oravec
parent f8c14a7671
commit d9c8524cdd
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
3 changed files with 18 additions and 3 deletions

View File

@ -298,7 +298,11 @@ MainApplication::MainApplication(int &argc, char** argv)
NetworkManager::registerSchemes(); NetworkManager::registerSchemes();
registerAllowedSchemes(); registerAllowedSchemes();
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
m_webProfile = isPrivate() ? new QWebEngineProfile() : QWebEngineProfile::defaultProfile(); m_webProfile = isPrivate() ? new QWebEngineProfile() : QWebEngineProfile::defaultProfile();
#else
m_webProfile = isPrivate() ? new QWebEngineProfile() : new QWebEngineProfile(QSL("Default"));
#endif
connect(m_webProfile, &QWebEngineProfile::downloadRequested, this, &MainApplication::downloadRequested); connect(m_webProfile, &QWebEngineProfile::downloadRequested, this, &MainApplication::downloadRequested);
m_webProfile->setNotificationPresenter([&] (std::unique_ptr<QWebEngineNotification> notification) { m_webProfile->setNotificationPresenter([&] (std::unique_ptr<QWebEngineNotification> notification) {
@ -404,6 +408,12 @@ MainApplication::~MainApplication()
delete m_cookieJar; delete m_cookieJar;
m_cookieJar = nullptr; m_cookieJar = nullptr;
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
// On Qt 6, deleting the web profile is necessary in order to make sure cache, cookies, etc. are flushed to disk.
delete m_webProfile;
m_webProfile = nullptr;
#endif
Settings::syncSettings(); Settings::syncSettings();
} }
@ -1006,7 +1016,11 @@ void MainApplication::loadSettings()
webSettings->setFontSize(QWebEngineSettings::MinimumLogicalFontSize, settings.value(QSL("MinimumLogicalFontSize"), 5).toInt()); webSettings->setFontSize(QWebEngineSettings::MinimumLogicalFontSize, settings.value(QSL("MinimumLogicalFontSize"), 5).toInt());
settings.endGroup(); settings.endGroup();
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QWebEngineProfile* profile = QWebEngineProfile::defaultProfile(); QWebEngineProfile* profile = QWebEngineProfile::defaultProfile();
#else
QWebEngineProfile* profile = m_webProfile;
#endif
profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies); profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies);
profile->setPersistentStoragePath(DataPaths::currentProfilePath()); profile->setPersistentStoragePath(DataPaths::currentProfilePath());

View File

@ -19,6 +19,7 @@
#include "browserwindow.h" #include "browserwindow.h"
#include "qztools.h" #include "qztools.h"
#include "settings.h" #include "settings.h"
#include "mainapplication.h"
#include <QWebEngineProfile> #include <QWebEngineProfile>
#include <QRegularExpression> #include <QRegularExpression>
@ -27,7 +28,7 @@ UserAgentManager::UserAgentManager(QObject* parent)
: QObject(parent) : QObject(parent)
, m_usePerDomainUserAgent(false) , m_usePerDomainUserAgent(false)
{ {
m_defaultUserAgent = QWebEngineProfile::defaultProfile()->httpUserAgent(); m_defaultUserAgent = mApp->webProfile()->httpUserAgent();
m_defaultUserAgent.replace(QRegularExpression(QSL("(QtWebEngine/[^\\s]+)")), QSL("Falkon/%1 \\1").arg(Qz::VERSION)); m_defaultUserAgent.replace(QRegularExpression(QSL("(QtWebEngine/[^\\s]+)")), QSL("Falkon/%1 \\1").arg(Qz::VERSION));
} }
@ -53,7 +54,7 @@ void UserAgentManager::loadSettings()
} }
const QString userAgent = m_globalUserAgent.isEmpty() ? m_defaultUserAgent : m_globalUserAgent; const QString userAgent = m_globalUserAgent.isEmpty() ? m_defaultUserAgent : m_globalUserAgent;
QWebEngineProfile::defaultProfile()->setHttpUserAgent(userAgent); mApp->webProfile()->setHttpUserAgent(userAgent);
} }
QString UserAgentManager::globalUserAgent() const QString UserAgentManager::globalUserAgent() const

View File

@ -310,7 +310,7 @@ Preferences::Preferences(BrowserWindow* window)
ui->allowCache->setChecked(settings.value("AllowLocalCache", true).toBool()); ui->allowCache->setChecked(settings.value("AllowLocalCache", true).toBool());
ui->removeCache->setChecked(settings.value("deleteCacheOnClose", false).toBool()); ui->removeCache->setChecked(settings.value("deleteCacheOnClose", false).toBool());
ui->cacheMB->setValue(settings.value("LocalCacheSize", 50).toInt()); ui->cacheMB->setValue(settings.value("LocalCacheSize", 50).toInt());
ui->cachePath->setText(settings.value("CachePath", QWebEngineProfile::defaultProfile()->cachePath()).toString()); ui->cachePath->setText(settings.value("CachePath", mApp->webProfile()->cachePath()).toString());
connect(ui->allowCache, &QAbstractButton::clicked, this, &Preferences::allowCacheChanged); connect(ui->allowCache, &QAbstractButton::clicked, this, &Preferences::allowCacheChanged);
connect(ui->changeCachePath, &QAbstractButton::clicked, this, &Preferences::changeCachePathClicked); connect(ui->changeCachePath, &QAbstractButton::clicked, this, &Preferences::changeCachePathClicked);
allowCacheChanged(ui->allowCache->isChecked()); allowCacheChanged(ui->allowCache->isChecked());