Skip to content

Commit

Permalink
Merge pull request #1921 from vs4vijay/theme-auto-detection
Browse files Browse the repository at this point in the history
automatically theme mode based on user preference
  • Loading branch information
a3957273 authored Feb 16, 2025
2 parents fb8e1be + feaf3dd commit 9ab990f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/web/App.mjs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class App {

this.initialiseSplitter();
this.loadLocalStorage();
this.manager.options.applyPreferredColorScheme();
this.populateOperationsList();
this.manager.setup();
this.manager.output.saveBombe();
Expand Down Expand Up @@ -536,6 +537,8 @@ class App {
// Read in theme from URI params
if (this.uriParams.theme) {
this.manager.options.changeTheme(Utils.escapeHtml(this.uriParams.theme));
} else {
this.manager.options.applyPreferredColorScheme();
}

window.dispatchEvent(this.manager.statechange);
Expand Down
8 changes: 8 additions & 0 deletions src/web/waiters/OptionsWaiter.mjs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ class OptionsWaiter {
themeSelect.selectedIndex = themeSelect.querySelector(`option[value="${theme}"`).index;
}

/**
* Applies the user's preferred color scheme using the `prefers-color-scheme` media query.
*/
applyPreferredColorScheme() {
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)").matches;
const theme = prefersDarkScheme ? "dark" : "classic";
this.changeTheme(theme);
}

/**
* Changes the console logging level.
Expand Down

0 comments on commit 9ab990f

Please sign in to comment.