From 492f0a5e32013d9c446aca55862897931f921d8e Mon Sep 17 00:00:00 2001 From: qxo <49526356@qq.com> Date: Sun, 16 Jan 2022 12:07:28 +0800 Subject: [PATCH] fix: try catch excepton in get_windows_dark_mode and global cache the check (#1587) * fix: try catch excepton on get_windows_dark_mode and global cache that check * add commitor email to CONTRIBUTORS * remove is_windows_dark_mode cache * avoid logging the missing key (dae) The check happens frequently, so this will fill up the user's console if we print it each time. --- CONTRIBUTORS | 1 + qt/aqt/theme.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 482d1c005..e40ed5660 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -89,6 +89,7 @@ lolilolicon Gesa Stupperich git9527 Vova Selin +qxo <49526356@qq.com> ******************** diff --git a/qt/aqt/theme.py b/qt/aqt/theme.py index 483b4dcfe..cd63fbbbf 100644 --- a/qt/aqt/theme.py +++ b/qt/aqt/theme.py @@ -327,7 +327,11 @@ def get_windows_dark_mode() -> bool: HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", ) - return not QueryValueEx(key, "AppsUseLightTheme")[0] + try: + return not QueryValueEx(key, "AppsUseLightTheme")[0] + except Exception as err: + # key reportedly missing or set to wrong type on some systems + return False def set_macos_dark_mode(enabled: bool) -> bool: