Skip to content

Commit 57e2f60

Browse files
committed
Auto light/dark theme: quering OS setting only once
1 parent a6e49d5 commit 57e2f60

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

guidata/qthelpers.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,10 @@ def is_dark_theme() -> bool:
118118
Returns:
119119
True if dark mode is enabled
120120
"""
121-
try:
122-
mode = os.environ[ENV_COLOR_MODE].lower()
123-
return mode == "dark" or (mode == "auto" and darkdetect.isDark())
124-
except KeyError:
125-
return darkdetect.isDark()
121+
mode = os.environ.get(ENV_COLOR_MODE, "auto").lower()
122+
if mode == "auto":
123+
os.environ[ENV_COLOR_MODE] = mode = "dark" if darkdetect.isDark() else "light"
124+
return mode == "dark"
126125

127126

128127
def get_color_theme() -> Literal["light", "dark"]:

0 commit comments

Comments
 (0)