diff --git a/src/libs/browser/settings.cpp b/src/libs/browser/settings.cpp index 11cb1eb..ceb2324 100644 --- a/src/libs/browser/settings.cpp +++ b/src/libs/browser/settings.cpp @@ -68,18 +68,19 @@ void Settings::applySettings() m_webProfile->settings()->setAttribute(QWebEngineSettings::ScrollAnimatorEnabled, m_appSettings->isSmoothScrollingEnabled); + // Qt 6.7+ does not require restart to enable dark mode. +#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0) + m_webProfile->settings()->setAttribute(QWebEngineSettings::ForceDarkMode, + m_appSettings->isDarkModeEnabled()); +#endif + // Apply custom CSS. // TODO: Apply to all open pages. m_webProfile->scripts()->clear(); // Remove all scripts first. // Qt 5.14+ uses native Chromium dark mode. #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) - const bool enableDarkMode - = m_appSettings->contentAppearance == Core::Settings::ContentAppearance::Dark - || (m_appSettings->contentAppearance == Core::Settings::ContentAppearance::Automatic - && m_appSettings->colorScheme() == Core::Settings::ColorScheme::Dark); - - if (enableDarkMode) { + if (m_appSettings->isDarkModeEnabled()) { setCustomStyleSheet(QStringLiteral("_zeal_darkstylesheet"), DarkModeCssUrl); } #endif diff --git a/src/libs/core/settings.cpp b/src/libs/core/settings.cpp index 8bcc6e6..3887338 100644 --- a/src/libs/core/settings.cpp +++ b/src/libs/core/settings.cpp @@ -73,6 +73,19 @@ Settings::~Settings() save(); } +bool Settings::isDarkModeEnabled() const +{ + if (contentAppearance == ContentAppearance::Dark) { + return true; + } + + if (contentAppearance == ContentAppearance::Automatic && colorScheme() == ColorScheme::Dark) { + return true; + } + + return false; +} + Zeal::Core::Settings::ColorScheme Settings::colorScheme() { #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) @@ -115,16 +128,12 @@ void Settings::load() settings->beginGroup(GroupContent); - // Dark mode needs to be applied before Qt WebEngine is initialized. contentAppearance = settings->value(QStringLiteral("appearance"), QVariant::fromValue(ContentAppearance::Automatic)).value(); -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - const bool enableDarkMode - = contentAppearance == ContentAppearance::Dark - || (contentAppearance == ContentAppearance::Automatic && colorScheme() == ColorScheme::Dark); - - if (enableDarkMode) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) && QT_VERSION < QT_VERSION_CHECK(6, 7, 0) + // Dark mode needs to be applied before Qt WebEngine is initialized. + if (isDarkModeEnabled()) { qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--blink-settings=forceDarkModeEnabled=true,darkModeInversionAlgorithm=4"); } #endif diff --git a/src/libs/core/settings.h b/src/libs/core/settings.h index cf79b3e..33f5e75 100644 --- a/src/libs/core/settings.h +++ b/src/libs/core/settings.h @@ -127,6 +127,8 @@ public: ~Settings() override; // Helper functions. + bool isDarkModeEnabled() const; + #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) typedef Qt::ColorScheme ColorScheme; #else diff --git a/src/libs/ui/settingsdialog.cpp b/src/libs/ui/settingsdialog.cpp index 92e4e3a..96a3c6c 100644 --- a/src/libs/ui/settingsdialog.cpp +++ b/src/libs/ui/settingsdialog.cpp @@ -285,6 +285,11 @@ void SettingsDialog::saveSettings() settings->isFuzzySearchEnabled = ui->fuzzySearchCheckBox->isChecked(); // Content Tab +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) && QT_VERSION < QT_VERSION_CHECK(6, 7, 0) + // Applying dark mode requires restart. + ui->appearanceLabel->setText(tr("Appearance (requires restart):")); +#endif + settings->defaultFontFamily = ui->defaultFontComboBox->currentData().toString(); settings->serifFontFamily = ui->serifFontComboBox->currentText(); settings->sansSerifFontFamily = ui->sansSerifFontComboBox->currentText(); diff --git a/src/libs/ui/settingsdialog.ui b/src/libs/ui/settingsdialog.ui index 58bab27..fbf461d 100644 --- a/src/libs/ui/settingsdialog.ui +++ b/src/libs/ui/settingsdialog.ui @@ -251,7 +251,7 @@ - Appearance (requires restart): + Appearance: