mirror of
https://github.com/gchq/CyberChef
synced 2025-12-21 18:53:20 +00:00
automatically theme mode based on user preference
Related to #1901 Implemented automatic dark theme change based on user preference using the `prefers-color-scheme` media query.
This commit is contained in:
3
src/web/App.mjs
Executable file → Normal file
3
src/web/App.mjs
Executable file → Normal file
@@ -60,6 +60,7 @@ class App {
|
|||||||
|
|
||||||
this.initialiseSplitter();
|
this.initialiseSplitter();
|
||||||
this.loadLocalStorage();
|
this.loadLocalStorage();
|
||||||
|
this.manager.options.applyPreferredColorScheme();
|
||||||
this.populateOperationsList();
|
this.populateOperationsList();
|
||||||
this.manager.setup();
|
this.manager.setup();
|
||||||
this.manager.output.saveBombe();
|
this.manager.output.saveBombe();
|
||||||
@@ -536,6 +537,8 @@ class App {
|
|||||||
// Read in theme from URI params
|
// Read in theme from URI params
|
||||||
if (this.uriParams.theme) {
|
if (this.uriParams.theme) {
|
||||||
this.manager.options.changeTheme(Utils.escapeHtml(this.uriParams.theme));
|
this.manager.options.changeTheme(Utils.escapeHtml(this.uriParams.theme));
|
||||||
|
} else {
|
||||||
|
this.manager.options.applyPreferredColorScheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
|
|||||||
8
src/web/waiters/OptionsWaiter.mjs
Executable file → Normal file
8
src/web/waiters/OptionsWaiter.mjs
Executable file → Normal file
@@ -163,6 +163,14 @@ class OptionsWaiter {
|
|||||||
themeSelect.selectedIndex = themeSelect.querySelector(`option[value="${theme}"`).index;
|
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.
|
* Changes the console logging level.
|
||||||
|
|||||||
Reference in New Issue
Block a user