Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions plugs/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The != operator does not exist in my definition of JavaScript, surprised that lint even allows it 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I wasn't 100% sure what this would/could return here. Because if you follow the definition, some are typed to return null and some return undefined and there are some parts were typescript doesn't check

await editor.setUiOption("darkMode", darkMode);
}
const markdownSyntaxRendering = await clientStore.get(
"markdownSyntaxRendering",
Expand Down
28 changes: 7 additions & 21 deletions web/editor_ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(() => {
Expand Down
Loading