返回 DeepSeek-Reasonix
conversationWidth.ts
根目录 / desktop / frontend / src / lib / conversationWidth.ts
1 export type ConversationWidth = "standard" | "full";
2
3 export const CONVERSATION_WIDTH_STORAGE_KEY = "reasonix-conv-width";
4 export const STANDARD_CONVERSATION_MAX_WIDTH = "960px";
5 export const FULL_CONVERSATION_MAX_WIDTH = "max(960px, 90%)";
6
7 export function normalizeConversationWidth(value: unknown): ConversationWidth {
8 return value === "full" ? "full" : "standard";
9 }
10
11 // localStorage is only an early-paint cache. The persisted desktop config is
12 // authoritative once DesktopStartupSettings / Settings has loaded.
13 export function getCachedConversationWidth(): ConversationWidth {
14 try {
15 return normalizeConversationWidth(localStorage.getItem(CONVERSATION_WIDTH_STORAGE_KEY));
16 } catch {
17 return "standard";
18 }
19 }
20
21 export function applyConversationWidth(value: unknown): ConversationWidth {
22 const width = normalizeConversationWidth(value);
23 if (typeof document !== "undefined") {
24 document.documentElement.style.setProperty(
25 "--maxw",
26 width === "full" ? FULL_CONVERSATION_MAX_WIDTH : STANDARD_CONVERSATION_MAX_WIDTH,
27 );
28 document.documentElement.setAttribute("data-conversation-width", width);
29 }
30 try {
31 localStorage.setItem(CONVERSATION_WIDTH_STORAGE_KEY, width);
32 } catch {
33 // Storage may be unavailable in hardened webviews; config sync still works.
34 }
35 return width;
36 }
37
38 export function initConversationWidth(): void {
39 applyConversationWidth(getCachedConversationWidth());
40 }
41
41 lines TYPESCRIPT