Skip to content

Commit 2a3b5be

Browse files
committed
fix(theme): correct dark/light mode check on Win10
`Utility::registryGetKeyValue` returns an invalid QVariant should the key not exist -- which is the case if that switch has never been toggled before. --> Fix this by ensuring the QVariant is valid, and only then try to convert it to a bool. Signed-off-by: Jyrki Gadinger <[email protected]>
1 parent 537fc38 commit 2a3b5be

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/libsync/theme.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,10 +1032,11 @@ bool Theme::darkMode() const
10321032

10331033
#ifdef Q_OS_WIN
10341034
static const auto darkModeSubkey = QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
1035-
if (!isWindows11OrGreater() &&
1036-
Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey) &&
1037-
!Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")).toBool()) {
1038-
return true;
1035+
if (!isWindows11OrGreater() && Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey)) {
1036+
if (const auto keyVariant = Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme"));
1037+
keyVariant.isValid() && !keyVariant.toBool()) {
1038+
return true;
1039+
}
10391040
}
10401041
#endif
10411042
return isDarkFromStyle();

0 commit comments

Comments
 (0)