Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webview] Guard programmatic preference change with marker file. Fixes JB#58269 #160

Merged
merged 1 commit into from Jun 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 24 additions & 10 deletions lib/webenginesettings.cpp
Expand Up @@ -13,9 +13,11 @@

#include <silicatheme.h>

#include <QtCore/QFile>
#include <QtCore/QLocale>
#include <QtCore/QSettings>
#include <QtCore/QSize>
#include <QtCore/QStandardPaths>
#include <QtCore/QtMath>
#include <QtGui/QGuiApplication>
#include <QtGui/QScreen>
Expand Down Expand Up @@ -96,6 +98,25 @@ void SailfishOS::WebEngineSettings::initialize()

SailfishOS::WebEngineSettings *engineSettings = instance();

// Infer and set Accept-Language header from the current system locale
QString langs;
QStringList locale = QLocale::system().name().split("_", QString::SkipEmptyParts);
if (locale.size() > 1) {
langs = QString("%1-%2,%3").arg(locale.at(0)).arg(locale.at(1)).arg(locale.at(0));
} else {
langs = locale.at(0);
}
engineSettings->setPreference(QStringLiteral("intl.accept_languages"),
QVariant::fromValue<QString>(langs));

// Guard preferences that should be written only once. If a preference needs to be
// forcefully written upon each start that should happen before this.
QString appConfig = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
QFile markerFile(QString("%1/__PREFS_WRITTEN__").arg(appConfig));
if (markerFile.exists()) {
return;
}

// Standard settings.
// TODO: Fix this so that it can be applied during runtime when QQuickItem based WebView is used with QQuickFlickable.
// At the moment just disable it to avoid unnecessary events being fired. JB#39581
Expand Down Expand Up @@ -160,16 +181,6 @@ void SailfishOS::WebEngineSettings::initialize()
engineSettings->setPreference(QStringLiteral("embedlite.inputItemSize"),
QVariant::fromValue<qreal>(silicaTheme->fontSizeSmall()));

// Infer and set Accept-Language header from the current system locale
QString langs;
QStringList locale = QLocale::system().name().split("_", QString::SkipEmptyParts);
if (locale.size() > 1) {
langs = QString("%1-%2,%3").arg(locale.at(0)).arg(locale.at(1)).arg(locale.at(0));
} else {
langs = locale.at(0);
}
engineSettings->setPreference(QStringLiteral("intl.accept_languages"),
QVariant::fromValue<QString>(langs));
engineSettings->setPreference(QStringLiteral("browser.enable_automatic_image_resizing"),
QVariant::fromValue<bool>(true));

Expand All @@ -178,6 +189,9 @@ void SailfishOS::WebEngineSettings::initialize()
QVariant::fromValue<bool>(true));
rainemak marked this conversation as resolved.
Show resolved Hide resolved

isInitialized = true;

markerFile.open(QIODevice::ReadWrite | QIODevice::Truncate);
markerFile.close();
}

/*!
Expand Down