mirror of
https://github.com/zadam/trilium.git
synced 2025-11-05 04:45:47 +01:00
fix(share): light theme not properly restored
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
const prefersDark = localStorage.getItem("theme") === "dark" || (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
const themeToLoad = getThemeToLoad();
|
||||||
if (prefersDark) {
|
if (themeToLoad === "dark") {
|
||||||
document.body.classList.add("theme-dark");
|
document.body.classList.add("theme-dark");
|
||||||
document.body.classList.remove("theme-light");
|
document.body.classList.remove("theme-light");
|
||||||
} else {
|
} else {
|
||||||
@@ -12,7 +12,7 @@ export default function setupThemeSelector() {
|
|||||||
|
|
||||||
const themeSelection: HTMLDivElement = document.querySelector(".theme-selection")!;
|
const themeSelection: HTMLDivElement = document.querySelector(".theme-selection")!;
|
||||||
themeSelection.classList.add("no-transition");
|
themeSelection.classList.add("no-transition");
|
||||||
themeSwitch.checked = prefersDark;
|
themeSwitch.checked = (themeToLoad === "dark");
|
||||||
setTimeout(() => themeSelection.classList.remove("no-transition"), 400);
|
setTimeout(() => themeSelection.classList.remove("no-transition"), 400);
|
||||||
|
|
||||||
themeSwitch?.addEventListener("change", () => {
|
themeSwitch?.addEventListener("change", () => {
|
||||||
@@ -27,3 +27,14 @@ export default function setupThemeSelector() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getThemeToLoad() {
|
||||||
|
const storedTheme = localStorage.getItem("theme");
|
||||||
|
if (storedTheme) {
|
||||||
|
// Respect user's choice if one has already been made.
|
||||||
|
return storedTheme;
|
||||||
|
} else if (window.matchMedia) {
|
||||||
|
// Fallback to browser's color preference otherwise.
|
||||||
|
return window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user