From e8cd327d4af6a19b9b39c2cfda3e5c85365437c7 Mon Sep 17 00:00:00 2001 From: noureddin Date: Tue, 9 Jul 2024 22:36:34 +0200 Subject: [PATCH] make darkmode follow system unless overriden --- zz.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/zz.py b/zz.py index d040e03..51d900c 100644 --- a/zz.py +++ b/zz.py @@ -40,10 +40,12 @@ def update_prefs(): # # checkboxes if 'imla' in storage: d['imla_chk'].checked = True - if 'light' in storage: d['dark_chk'].checked = False if 'notajweed' in storage: d['taj_chk'].checked = False if 'noquick' in storage: d['quick_chk'].checked = False if 'byword' in storage: d['byword_chk'].checked = True + # darkmode: following the system, unless overriden + if 'dark' in storage: d['dark_chk'].checked = storage['dark'] == 'Y' + else: d['dark_chk'].checked = w.matchMedia('(prefers-color-scheme: dark)').matches # # warning if 'warn' in storage: @@ -53,7 +55,7 @@ def update_prefs(): def load_bool(name): return name in storage and bool(storage[name]) -def store_bool(name, b): +def store_bool(name, b=True): if b: storage[name] = "Y" else: @@ -849,7 +851,7 @@ def __imla_btn_click(ev): @bind(d['dark_btn'], 'click') def __dark_btn_click(ev): d['dark_chk'].checked ^= 1 # toggle - store_bool('light', not d['dark_chk'].checked) + storage['dark'] = 'Y' if d['dark_chk'].checked else 'N' update_otherparams() @bind(d['taj_btn'], 'click') @@ -983,7 +985,7 @@ def zz_set_tajweed(v): def zz_set_dark(dark): d['dark_chk'].checked = dark - store_bool('light', not dark) + storage['dark'] = 'Y' if dark else 'N' update_otherparams() w.zz_set_dark = zz_set_dark