ChemPal Documentation - v1.6.0
    Preparing search index...

    Function initThemeAwareToolbarIcon

    • Initializes the theme-aware toolbar icon: applies the icon matching the current prefers-color-scheme and updates it whenever the scheme changes.

      Safe to call unconditionally at startup — it no-ops in any context lacking matchMedia or chrome.action.setIcon (tests, the Vite dev preview, a service worker, or a browser that exposes neither), so it never throws.

      Returns void

      Nothing; the toolbar icon is updated as a side effect.

      // In the app entry point (main.tsx):
      initThemeAwareToolbarIcon();
      export function initThemeAwareToolbarIcon(): void {
      if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
      return;
      }
      if (typeof chrome === 'undefined' || chrome.action?.setIcon === undefined) {
      return;
      }

      const darkScheme = window.matchMedia('(prefers-color-scheme: dark)');
      void applyToolbarIcon(darkScheme.matches ? 'dark' : 'light');
      darkScheme.addEventListener('change', (event) => {
      void applyToolbarIcon(event.matches ? 'dark' : 'light');
      });
      }