返回 DeepSeek-Reasonix
displayMode.ts
根目录 / desktop / frontend / src / lib / displayMode.ts
1 export type DisplayMode = "standard" | "compact";
2
3 const DISPLAY_MODE_KEY = "reasonix-display-mode";
4 const DISPLAY_MODE_EVENT = "reasonix:display-mode";
5
6 export function getDisplayMode(): DisplayMode {
7 if (typeof localStorage === "undefined") return "standard";
8 const stored = localStorage.getItem(DISPLAY_MODE_KEY);
9 if (stored === "standard" || stored === "compact") return stored;
10 if (stored === "minimal") return "compact";
11 return "standard";
12 }
13
14 export function setDisplayMode(mode: DisplayMode): void {
15 localStorage.setItem(DISPLAY_MODE_KEY, mode);
16 window.dispatchEvent(new CustomEvent(DISPLAY_MODE_EVENT, { detail: mode }));
17 }
18
19 /** Adopts the toml-persisted mode at boot so config is the source of truth across machines. */
20 export function hydrateDisplayMode(mode: string | undefined): void {
21 const next: DisplayMode | undefined = mode === "standard" || mode === "compact" ? mode : mode === "minimal" ? "compact" : undefined;
22 if (!next) return;
23 if (next === getDisplayMode()) return;
24 setDisplayMode(next);
25 }
26
27 export function onDisplayModeChange(cb: (mode: DisplayMode) => void): () => void {
28 const handler = (e: Event) => cb((e as CustomEvent).detail as DisplayMode);
29 window.addEventListener(DISPLAY_MODE_EVENT, handler);
30 return () => window.removeEventListener(DISPLAY_MODE_EVENT, handler);
31 }
32
32 lines TYPESCRIPT