Skip to content

Commit 4f1609f

Browse files
Allow universal themes
1 parent 87f432d commit 4f1609f

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/addon/config.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List
1+
from typing import Any, List
22
from pathlib import Path
33
import json
44

@@ -146,20 +146,23 @@ def themes_list() -> List[str]:
146146
return themes
147147

148148

149+
def replace_conf_color(conf: ConfigManager, theme_json: Any, dark_mode: bool) -> None:
150+
modeidx = 2 if dark_mode else 1
151+
152+
for color in theme_json["colors"]:
153+
conf[f"colors.{color}.{modeidx}"] = theme_json["colors"][color][modeidx]
154+
155+
149156
def apply_theme(conf_window: ConfigWindow, theme: str) -> None:
150157
theme_path = THEMES_DIR / f"{theme}.json"
151158
theme_json = json.loads(theme_path.read_text())
152159

153-
if theme.startswith("(dark)"):
154-
modeidx = 2
155-
elif theme.startswith("(light)"):
156-
modeidx = 1
157-
else:
158-
tooltip("Invalid theme name<br />Theme name must start with (light) or (dark)")
159-
return
160-
161-
for color in theme_json["colors"]:
162-
conf[f"colors.{color}.{modeidx}"] = theme_json["colors"][color][modeidx]
160+
# Dark mode or universal
161+
if not theme.startswith("(dark)"):
162+
replace_conf_color(conf, theme_json, False)
163+
# Light mode or universal
164+
if not theme.startswith("(light)"):
165+
replace_conf_color(conf, theme_json, True)
163166

164167
conf_window.update_widgets()
165168
conf_window.main_tab.setCurrentIndex(0)

0 commit comments

Comments
 (0)