From 4e11bd549c57a9dbd67ec0148e71fc7e2a2ca6a8 Mon Sep 17 00:00:00 2001 From: thzxx Date: Tue, 7 Apr 2026 10:50:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=80=E5=87=BA=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E6=97=B6=E8=87=AA=E5=8A=A8=E9=87=8A=E6=94=BE=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=98=BE=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/main.ts | 2 ++ src/main/preload.ts | 3 +++ src/renderer/main.ts | 9 +++++++++ src/renderer/types.d.ts | 1 + 4 files changed, 15 insertions(+) diff --git a/src/main/main.ts b/src/main/main.ts index 3e11c9a..b466956 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -165,4 +165,6 @@ app.on('window-all-closed', () => { app.on('before-quit', () => { isQuitting = true; + // 通知渲染进程释放显存 + mainWindow?.webContents.send('app-quit'); }); diff --git a/src/main/preload.ts b/src/main/preload.ts index c7afa48..8c5b942 100644 --- a/src/main/preload.ts +++ b/src/main/preload.ts @@ -33,6 +33,9 @@ contextBridge.exposeInMainWorld('metonaDesktop', { onTrayAction: (callback: (action: string) => void) => { ipcRenderer.on('tray-action', (_: unknown, action: string) => callback(action)); }, + onAppQuit: (callback: () => void) => { + ipcRenderer.on('app-quit', () => callback()); + }, removeAllListeners: (channel: string) => { ipcRenderer.removeAllListeners(channel); } diff --git a/src/renderer/main.ts b/src/renderer/main.ts index 0f4e02b..f225f5b 100644 --- a/src/renderer/main.ts +++ b/src/renderer/main.ts @@ -77,6 +77,15 @@ function setupDesktopIntegration(): void { } }) as EventListener); + // 退出时释放显存 + bridge.onAppQuit(() => { + const api = state.get(KEYS.API); + const model = state.get('_defaultModel', ''); + if (api && model) { + api.chat({ model, messages: [], keep_alive: 0 } as any).catch(() => {}); + } + }); + // 桌面端快捷键 document.addEventListener('keydown', (e) => { if (e.ctrlKey && e.key === 'n') { diff --git a/src/renderer/types.d.ts b/src/renderer/types.d.ts index 0d2f556..7416700 100644 --- a/src/renderer/types.d.ts +++ b/src/renderer/types.d.ts @@ -214,6 +214,7 @@ export interface MetonaDesktopAPI { openExternal: (url: string) => void; onMenuAction: (callback: (action: string) => void) => void; onTrayAction: (callback: (action: string) => void) => void; + onAppQuit: (callback: () => void) => void; removeAllListeners: (channel: string) => void; }