The new theme mode to set ("dark", "light", or "system").
A promise that resolves to true if dark mode is enabled, false otherwise.
export async function setTheme(newTheme: ThemeMode) {
let isDarkMode = false;
switch (newTheme) {
case "dark":
await window.themeMode.dark();
isDarkMode = true;
break;
case "light":
await window.themeMode.light();
isDarkMode = false;
break;
case "system": {
isDarkMode = await window.themeMode.system();
break;
}
}
updateDocumentTheme(isDarkMode);
storage.setItem(THEME_KEY, newTheme);
// Notify any listeners that theme has changed
document.dispatchEvent(new CustomEvent("themeToggled"));
return isDarkMode;
}
Sets the application theme to the specified mode and updates the DOM and local storage.