Skip to content

Build your personal knowledge base with Trilium Notes

Close #7932

Adorian Doran44dc8cf00d3d
diff --git a/apps/client/src/widgets/containers/root_container.ts b/apps/client/src/widgets/containers/root_container.ts
index 2e852033c4..698e741c37 100644
--- a/apps/client/src/widgets/containers/root_container.ts
+++ b/apps/client/src/widgets/containers/root_container.ts
@@ -34,6 +34,7 @@ export default class RootContainer extends FlexContainer<BasicWidget> {
window.visualViewport?.addEventListener("resize", () => this.#onMobileResize());
}
+ this.#initTheme();
this.#setDeviceSpecificClasses();
this.#setMaxContentWidth();
this.#setMotion();
@@ -67,6 +68,20 @@ export default class RootContainer extends FlexContainer<BasicWidget> {
}
}
+ #initTheme() {
+ const colorSchemeChangeObserver = matchMedia("(prefers-color-scheme: dark)")
+ colorSchemeChangeObserver.addEventListener("change", () => this.#updateColorScheme());
+
+ this.#updateColorScheme();
+ }
+
+ #updateColorScheme() {
+ const colorScheme = readCssVar(document.body, "theme-style").asString();
+
+ document.body.classList.toggle("light-theme", colorScheme === "light");
+ document.body.classList.toggle("dark-theme", colorScheme === "dark");
+ }
+
#onMobileResize() {
const viewportHeight = window.visualViewport?.height ?? window.innerHeight;
const windowHeight = Math.max(window.innerHeight, this.originalWindowHeight); // inner height changes when keyboard is opened, we need to compare with the original height to detect it.