Skip to content

Commit

Permalink
Use registry-based dark mode detection on <= Windows 10
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Nov 5, 2024
1 parent c314538 commit dbf4d1d
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,17 +1022,29 @@ QVariantMap Theme::systemPalette()
bool Theme::darkMode()
{
connectToPaletteSignal();
switch (qGuiApp->styleHints()->colorScheme())
{
case Qt::ColorScheme::Dark:
return true;
case Qt::ColorScheme::Light:
const auto isDarkFromStyle = [] {
switch (qGuiApp->styleHints()->colorScheme())
{
case Qt::ColorScheme::Dark:
return true;
case Qt::ColorScheme::Light:
return false;
case Qt::ColorScheme::Unknown:
return Theme::isDarkColor(QGuiApplication::palette().window().color());
}

return false;
case Qt::ColorScheme::Unknown:
return Theme::isDarkColor(QGuiApplication::palette().window().color());
}
};

return false;
#ifdef Q_OS_WIN
static const auto darkModeSubkey = QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
if (!IsWindows11OrGreater() &&
Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey) &&
!Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")).toBool()) {
return true;
}
#endif
return isDarkFromStyle();
}

void Theme::setOverrideServerUrl(const QString &overrideServerUrl)
Expand Down

0 comments on commit dbf4d1d

Please sign in to comment.