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; }