diff --git a/apps/desktop/src/demo/api.ts b/apps/desktop/src/demo/api.ts index e5b8e80..cc21e8f 100644 --- a/apps/desktop/src/demo/api.ts +++ b/apps/desktop/src/demo/api.ts @@ -94,7 +94,7 @@ let proxySettings: ProxySettings = { has_password: false, }; let tabSettings: TabSettings = { mode: "public", address: "" }; -let storage: StatisticsStorage = { bytes: 26_004_480, call_count: calls.length, trace_count: calls.length }; +let storage: StatisticsStorage = { call_count: calls.length, trace_count: calls.length }; export function installDemoApi() { const nativeFetch = window.fetch.bind(window); @@ -151,9 +151,7 @@ export function installDemoApi() { if (path === "/settings/storage/statistics" && method === "GET") return json(storage); if (path === "/settings/storage/statistics") { const scope = (body as { scope?: string } | null)?.scope ?? "details"; - storage = scope === "all" - ? { bytes: 0, call_count: 0, trace_count: 0 } - : { ...storage, bytes: 0 }; + storage = scope === "all" ? { call_count: 0, trace_count: 0 } : storage; return json(storage); } if (path === "/settings/proxy" && method === "GET") return json(proxySettings); diff --git a/apps/desktop/src/features/settings/SettingsPage.tsx b/apps/desktop/src/features/settings/SettingsPage.tsx index 700c416..212c2fd 100644 --- a/apps/desktop/src/features/settings/SettingsPage.tsx +++ b/apps/desktop/src/features/settings/SettingsPage.tsx @@ -40,13 +40,16 @@ export function SettingsPage() { const [editingTab, setEditingTab] = useState(false); const [savingTab, setSavingTab] = useState(false); useEffect(() => { - void Promise.all([api.statisticsStorage(), api.proxySettings(), api.tabSettings()]).then(([nextStorage, nextProxy, nextTab]) => { - setStorage(nextStorage); - setOutboundProxy(nextProxy); - setProxyDraft({ mode: nextProxy.mode, address: nextProxy.address, auth_enabled: nextProxy.auth_enabled, username: nextProxy.username, password: "" }); - setTabSettings(nextTab); - setTabDraft(nextTab); - }).catch((cause) => message(cause instanceof Error ? cause.message : String(cause))); + const report = (cause: unknown) => message(cause instanceof Error ? cause.message : String(cause)); + void api.statisticsStorage().then(setStorage).catch(report); + void api.proxySettings().then((next) => { + setOutboundProxy(next); + setProxyDraft({ mode: next.mode, address: next.address, auth_enabled: next.auth_enabled, username: next.username, password: "" }); + }).catch(report); + void api.tabSettings().then((next) => { + setTabSettings(next); + setTabDraft(next); + }).catch(report); }, [message]); useEffect(() => { setProxyPort(String(ports.proxy_port)); @@ -149,14 +152,6 @@ export function SettingsPage() { setSavingTab(false); } }; - const formatBytes = (bytes: number) => { - if (bytes < 1024) return `${bytes} B`; - const units = ["KB", "MB", "GB", "TB"]; - let value = bytes / 1024; - let unit = 0; - while (value >= 1024 && unit < units.length - 1) { value /= 1024; unit += 1; } - return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[unit]}`; - }; const clearTitle = clearScope === "all" ? t("确定要清理全部统计数据吗?") : t("确定要清理详细记录吗?"); const clearDescription = clearScope === "all" ? t("所有调用汇总、详细内容和追踪记录都会被删除。模型配置、CA 和应用设置不会受到影响,此操作无法撤销。") @@ -283,7 +278,7 @@ export function SettingsPage() {