Update app.py

#3
by volivers - opened
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -2341,13 +2341,14 @@ SELECTION_JS = """
2341
  }
2342
  function toggleDark() {
2343
  const url = new URL(window.location);
2344
- const isDark = url.searchParams.get('__theme') === 'dark';
 
 
2345
  url.searchParams.set('__theme', isDark ? 'light' : 'dark');
2346
  window.location.href = url.href;
2347
  }
2348
  window._lolaby_applyTheme = applyTheme;
2349
  window._lolaby_toggleDark = toggleDark;
2350
-
2351
  window.addEventListener('load', function () {
2352
  const url = new URL(window.location);
2353
  const isDark = url.searchParams.get('__theme') === 'dark';
@@ -2358,7 +2359,7 @@ SELECTION_JS = """
2358
  window.location.replace(url.href);
2359
  return;
2360
  }
2361
- applyTheme(isDark);
2362
  });
2363
  })();
2364
 
 
2341
  }
2342
  function toggleDark() {
2343
  const url = new URL(window.location);
2344
+ const isBrowserDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
2345
+ const noTheme = !url.searchParams.has('__theme');
2346
+ const isDark = noTheme ? isBrowserDark : url.searchParams.get('__theme') === 'dark';
2347
  url.searchParams.set('__theme', isDark ? 'light' : 'dark');
2348
  window.location.href = url.href;
2349
  }
2350
  window._lolaby_applyTheme = applyTheme;
2351
  window._lolaby_toggleDark = toggleDark;
 
2352
  window.addEventListener('load', function () {
2353
  const url = new URL(window.location);
2354
  const isDark = url.searchParams.get('__theme') === 'dark';
 
2359
  window.location.replace(url.href);
2360
  return;
2361
  }
2362
+ applyTheme(noTheme ? isBrowserDark : isDark);
2363
  });
2364
  })();
2365