diff --git a/plugs/editor/editor.ts b/plugs/editor/editor.ts index e79ad6e9e..07935e679 100644 --- a/plugs/editor/editor.ts +++ b/plugs/editor/editor.ts @@ -9,8 +9,12 @@ export async function setEditorMode() { if (await clientStore.get("vimMode")) { await editor.setUiOption("vimMode", true); } - if (await clientStore.get("darkMode")) { - await editor.setUiOption("darkMode", true); + // Only set the darkmode value if it was deliberatly set in the clientstore, + // otherwise leave it so the client can choose depending on the system + // settings + const darkMode = await clientStore.get("darkMode"); + if (darkMode != null) { + await editor.setUiOption("darkMode", darkMode); } const markdownSyntaxRendering = await clientStore.get( "markdownSyntaxRendering", diff --git a/web/editor_ui.tsx b/web/editor_ui.tsx index 0643e5970..faa8d2940 100644 --- a/web/editor_ui.tsx +++ b/web/editor_ui.tsx @@ -18,7 +18,6 @@ import { runScopeHandlers } from "@codemirror/view"; import type { Client } from "./client.ts"; import { Panel } from "./components/panel.tsx"; import { safeRun } from "../lib/async.ts"; -import { clientStoreSyscalls } from "./syscalls/clientStore.ts"; import type { FilterOption } from "@silverbulletmd/silverbullet/type/client"; import { getNameFromPath, @@ -103,28 +102,15 @@ export class MainUI { }, [viewState.uiOptions.vimMode]); useEffect(() => { - clientStoreSyscalls(client.ds)["clientStore.get"]( - {}, - "darkMode", - ).then((storedDarkModePreference: boolean | undefined) => { - let theme: "dark" | "light"; - if (storedDarkModePreference === true) { - theme = "dark"; - } else if (storedDarkModePreference === false) { - theme = "light"; - } else { - theme = globalThis.matchMedia("(prefers-color-scheme: dark)").matches - ? "dark" - : "light"; - } + const darkMode = viewState.uiOptions.darkMode === undefined + ? globalThis.matchMedia("(prefers-color-scheme: dark)").matches + : viewState.uiOptions.darkMode; - viewState.uiOptions.darkMode = theme === "dark"; - document.documentElement.dataset.theme = theme; + document.documentElement.dataset.theme = darkMode ? "dark" : "light"; - if (this.client.isDocumentEditor()) { - this.client.documentEditor.updateTheme(); - } - }); + if (this.client.isDocumentEditor()) { + this.client.documentEditor.updateTheme(); + } }, [viewState.uiOptions.darkMode]); useEffect(() => {