Webui: Add color scheme switcher

Closes #21600
This commit is contained in:
sledgehammer999 2024-10-15 01:33:25 +03:00
commit 3aefc16c57
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2
4 changed files with 53 additions and 17 deletions

View file

@ -1738,6 +1738,19 @@ window.addEventListener("load", () => {
window.qBittorrent.Cache.preferences.init();
window.qBittorrent.Cache.qbtVersion.init();
// Setup color scheme switching
const colorSchemeQuery = window.matchMedia("(prefers-color-scheme: dark)");
const updateColorScheme = () => {
const root = document.documentElement;
const colorScheme = LocalPreferences.get("color_scheme");
const validScheme = (colorScheme === "light") || (colorScheme === "dark");
const isDark = colorSchemeQuery.matches;
root.classList.toggle("dark", ((!validScheme && isDark) || (colorScheme === "dark")));
};
colorSchemeQuery.addEventListener("change", updateColorScheme);
updateColorScheme();
// switch to previously used tab
const previouslyUsedTab = LocalPreferences.get("selected_window_tab", "transfers");
switch (previouslyUsedTab) {