1
0
mirror of synced 2025-02-22 04:49:47 +01:00

Merge pull request #1921 from vs4vijay/theme-auto-detection

automatically theme mode based on user preference
This commit is contained in:
a3957273 2025-02-16 01:36:28 +00:00 committed by GitHub
commit 9ab990ff59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

3
src/web/App.mjs Executable file → Normal file
View File

@ -60,6 +60,7 @@ class App {
this.initialiseSplitter();
this.loadLocalStorage();
this.manager.options.applyPreferredColorScheme();
this.populateOperationsList();
this.manager.setup();
this.manager.output.saveBombe();
@ -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);

8
src/web/waiters/OptionsWaiter.mjs Executable file → Normal file
View File

@ -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.