From 3ec7e23d7c319ae79b99adefb0bf3a10515d0964 Mon Sep 17 00:00:00 2001 From: Zoom Date: Thu, 15 Sep 2022 02:04:19 +0000 Subject: [PATCH] Fix Windows dark mode detection: OpenKey can fail (#2068) * Fix Windows dark mode detection: OpenKey can fail #1497 introduced reading hardcoded Windows Registry key, which assumes key exists. This is not true on Windows 7. Later addition of `try-except` block missed that OpenKey might fail. This fix allows launching current version of Anki on Windows 7 when installed with Pip with the modified Python 3.9 installation. * Update CONTRIBUTORS CI req: Add myself to the contributor list --- CONTRIBUTORS | 1 + qt/aqt/theme.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 57ffceebf..b04a3e05a 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -105,6 +105,7 @@ dobefore <1432338032@qq.com> Bart Louwers Sam Penny Yutsuten +Zoom ******************** diff --git a/qt/aqt/theme.py b/qt/aqt/theme.py index c4393be01..63b3318b3 100644 --- a/qt/aqt/theme.py +++ b/qt/aqt/theme.py @@ -297,11 +297,11 @@ def get_windows_dark_mode() -> bool: QueryValueEx, ) - key = OpenKey( - HKEY_CURRENT_USER, - r"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", - ) try: + key = OpenKey( + HKEY_CURRENT_USER, + r"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", + ) return not QueryValueEx(key, "AppsUseLightTheme")[0] except Exception as err: # key reportedly missing or set to wrong type on some systems