From 58ef27206153381cfc25389c1b153e68f838eabc Mon Sep 17 00:00:00 2001 From: thzxx Date: Tue, 7 Apr 2026 01:28:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=A1=8C=E9=9D=A2?= =?UTF-8?q?=E9=9B=86=E6=88=90=E5=A4=B1=E6=95=88=20+=20=E6=B8=85=E7=90=86?= =?UTF-8?q?=E6=AD=BB=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - main.ts: window.__metonaBridge → window.metonaDesktop(与 preload.ts 对齐) - 删除 DesktopBridge 接口和 __metonaBridge 类型(从未使用) - 删除 extractDocument(定义了但无调用) - 删除 logIPC(导出了但零引用) - 删除 getMessagesContainer(导出了但无调用) - SAFE_DATA_TYPES 去掉多余的 export - vite.config.ts 移除未使用的 server 配置 --- src/renderer/components/chat-area.ts | 4 ---- src/renderer/main.ts | 2 +- src/renderer/services/document-processor.ts | 4 ---- src/renderer/services/log-service.ts | 1 - src/renderer/types.d.ts | 20 -------------------- src/renderer/utils/sanitizer.ts | 2 +- vite.config.ts | 3 --- 7 files changed, 2 insertions(+), 34 deletions(-) diff --git a/src/renderer/components/chat-area.ts b/src/renderer/components/chat-area.ts index 56d02ec..46fef38 100644 --- a/src/renderer/components/chat-area.ts +++ b/src/renderer/components/chat-area.ts @@ -373,10 +373,6 @@ export function appendSystemMessage(text: string, tempClass?: string): void { scrollToBottom(); } -export function getMessagesContainer(): HTMLElement { - return messagesContainerEl; -} - export function clearMessages(): void { messagesContainerEl.innerHTML = ''; currentPlaceholder = null; diff --git a/src/renderer/main.ts b/src/renderer/main.ts index 40cfe11..1225d41 100644 --- a/src/renderer/main.ts +++ b/src/renderer/main.ts @@ -43,7 +43,7 @@ function initHelpModal(): void { } function setupDesktopIntegration(): void { - const bridge = window.__metonaBridge; + const bridge = window.metonaDesktop; if (!bridge || !bridge.isDesktop) { logDebug('非桌面环境,跳过桌面集成'); return; diff --git a/src/renderer/services/document-processor.ts b/src/renderer/services/document-processor.ts index 81ac8a3..ac24e85 100644 --- a/src/renderer/services/document-processor.ts +++ b/src/renderer/services/document-processor.ts @@ -58,10 +58,6 @@ function splitSentences(text: string): string[] { return parts.filter(p => p.trim()).map(p => p.trim() + ' '); } -export function extractDocument(content: string, filename: string): { text: string; filename: string } { - return { text: content, filename }; -} - export function createChunkMetadata(chunk: string, index: number, docId: string, filename: string) { return { id: `${docId}_chunk_${index}`, diff --git a/src/renderer/services/log-service.ts b/src/renderer/services/log-service.ts index 6456c27..e14aa47 100644 --- a/src/renderer/services/log-service.ts +++ b/src/renderer/services/log-service.ts @@ -183,5 +183,4 @@ export function logSession(action: string, detail?: string): void { addLog('info export function logMemory(action: string, detail?: string): void { addLog('debug', `记忆: ${action}`, detail); } export function logRAG(action: string, detail?: string): void { addLog('info', `RAG: ${action}`, detail); } export function logSetting(key: string, value: string): void { addLog('debug', `设置: ${key}`, value); } -export function logIPC(action: string, detail?: string): void { addLog('debug', `IPC: ${action}`, detail); } export function logInit(msg: string): void { addLog('info', `初始化: ${msg}`); } diff --git a/src/renderer/types.d.ts b/src/renderer/types.d.ts index 1e1536f..5cc31b1 100644 --- a/src/renderer/types.d.ts +++ b/src/renderer/types.d.ts @@ -234,25 +234,6 @@ export interface SaveFileOptions { filters?: Array<{ name: string; extensions: string[] }>; } -// ── 桌面 Bridge 接口 ── - -export interface DesktopBridge { - isDesktop: boolean; - getInfo: () => Promise<{ platform: string; version: string; arch?: string; electronVersion?: string; userDataPath?: string }>; - openFile: (filters?: Array<{ name: string; extensions: string[] }>) => Promise; - saveFile: (options?: SaveFileOptions) => Promise; - readFile: (filePath: string) => Promise<{ success: boolean; content?: string; name?: string; error?: string }>; - writeFile: (filePath: string, content: string) => Promise<{ success: boolean; error?: string }>; - notify: (title: string, body: string) => void; - minimize: () => void; - maximize: () => void; - close: () => void; - openExternal: (url: string) => void; - onMenuAction: (callback: (action: string) => void) => void; - onTrayAction: (callback: (action: string) => void) => void; - off: (channel: string) => void; -} - // ── State Keys ── export type StateKey = @@ -333,7 +314,6 @@ export type AgentState = 'idle' | 'sending' | 'accumulating' | 'executing' | 'co declare global { interface Window { metonaDesktop?: MetonaDesktopAPI; - __metonaBridge?: DesktopBridge; } } diff --git a/src/renderer/utils/sanitizer.ts b/src/renderer/utils/sanitizer.ts index cf51362..e5fa47c 100644 --- a/src/renderer/utils/sanitizer.ts +++ b/src/renderer/utils/sanitizer.ts @@ -3,7 +3,7 @@ */ export const SAFE_URI_SCHEMES = new Set(['http:', 'https:', 'mailto:', 'tel:', 'ftp:', 'ftps:', 'xmpp:']); -export const SAFE_DATA_TYPES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/svg+xml']); +const SAFE_DATA_TYPES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/svg+xml']); const ALLOWED_TAGS = new Set([ 'a', 'abbr', 'b', 'blockquote', 'br', 'code', 'del', 'details', 'div', diff --git a/vite.config.ts b/vite.config.ts index 1a1f803..00b683a 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -14,7 +14,4 @@ export default defineConfig({ css: { preprocessorOptions: {}, }, - server: { - port: 5173, - }, });