feat: 退出应用时自动释放模型显存
This commit is contained in:
@@ -165,4 +165,6 @@ app.on('window-all-closed', () => {
|
|||||||
|
|
||||||
app.on('before-quit', () => {
|
app.on('before-quit', () => {
|
||||||
isQuitting = true;
|
isQuitting = true;
|
||||||
|
// 通知渲染进程释放显存
|
||||||
|
mainWindow?.webContents.send('app-quit');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ contextBridge.exposeInMainWorld('metonaDesktop', {
|
|||||||
onTrayAction: (callback: (action: string) => void) => {
|
onTrayAction: (callback: (action: string) => void) => {
|
||||||
ipcRenderer.on('tray-action', (_: unknown, action: string) => callback(action));
|
ipcRenderer.on('tray-action', (_: unknown, action: string) => callback(action));
|
||||||
},
|
},
|
||||||
|
onAppQuit: (callback: () => void) => {
|
||||||
|
ipcRenderer.on('app-quit', () => callback());
|
||||||
|
},
|
||||||
removeAllListeners: (channel: string) => {
|
removeAllListeners: (channel: string) => {
|
||||||
ipcRenderer.removeAllListeners(channel);
|
ipcRenderer.removeAllListeners(channel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,15 @@ function setupDesktopIntegration(): void {
|
|||||||
}
|
}
|
||||||
}) as EventListener);
|
}) as EventListener);
|
||||||
|
|
||||||
|
// 退出时释放显存
|
||||||
|
bridge.onAppQuit(() => {
|
||||||
|
const api = state.get<OllamaAPI | null>(KEYS.API);
|
||||||
|
const model = state.get<string>('_defaultModel', '');
|
||||||
|
if (api && model) {
|
||||||
|
api.chat({ model, messages: [], keep_alive: 0 } as any).catch(() => {});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 桌面端快捷键
|
// 桌面端快捷键
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
if (e.ctrlKey && e.key === 'n') {
|
if (e.ctrlKey && e.key === 'n') {
|
||||||
|
|||||||
Vendored
+1
@@ -214,6 +214,7 @@ export interface MetonaDesktopAPI {
|
|||||||
openExternal: (url: string) => void;
|
openExternal: (url: string) => void;
|
||||||
onMenuAction: (callback: (action: string) => void) => void;
|
onMenuAction: (callback: (action: string) => void) => void;
|
||||||
onTrayAction: (callback: (action: string) => void) => void;
|
onTrayAction: (callback: (action: string) => void) => void;
|
||||||
|
onAppQuit: (callback: () => void) => void;
|
||||||
removeAllListeners: (channel: string) => void;
|
removeAllListeners: (channel: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user