• Sets the application theme to the specified mode and updates the DOM and local storage.

    Parameters

    • newTheme: ThemeMode

      The new theme mode to set ("dark", "light", or "system").

    Returns Promise<boolean>

    A promise that resolves to true if dark mode is enabled, false otherwise.

    Also dispatches a "themeToggled" event on the document.

    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;
    }