From 44e850dfa3c9e243d6da8d3ec37fd8c265fb6028 Mon Sep 17 00:00:00 2001 From: Elijah R Date: Tue, 9 Apr 2024 19:51:13 -0400 Subject: [PATCH] detect dark theme from browser --- src/ts/main.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ts/main.ts b/src/ts/main.ts index 64ff219..9c37935 100644 --- a/src/ts/main.ts +++ b/src/ts/main.ts @@ -1275,11 +1275,14 @@ document.addEventListener('DOMContentLoaded', async () => { }); // Load theme var _darktheme : boolean; - if (localStorage.getItem("cvm-dark-theme") === "0") - loadColorTheme(false); - else + // Check if dark theme is set in local storage + if (localStorage.getItem("cvm-dark-theme") !== null) + loadColorTheme(localStorage.getItem("cvm-dark-theme") === "1"); + // Otherwise, try to detect the system theme + else if (window.matchMedia('(prefers-color-scheme: dark)').matches) loadColorTheme(true); - + else + loadColorTheme(false); // Initialize authentication if enabled if (Config.Auth.Enabled) { auth = new AuthManager(Config.Auth.APIEndpoint);