mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-05-03 11:41:17 +08:00
feat: 关闭软件时清理 Worker
This commit is contained in:
@@ -2,7 +2,7 @@ import { app, shell, BrowserWindow, protocol, nativeTheme } from 'electron'
|
|||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { optimizer, is, platform } from '@electron-toolkit/utils'
|
import { optimizer, is, platform } from '@electron-toolkit/utils'
|
||||||
import { checkUpdate } from './update'
|
import { checkUpdate } from './update'
|
||||||
import mainIpcMain from './ipcMain'
|
import mainIpcMain, { cleanup } from './ipcMain'
|
||||||
import { initAnalytics, trackDailyActive } from './analytics'
|
import { initAnalytics, trackDailyActive } from './analytics'
|
||||||
import { initProxy } from './network/proxy'
|
import { initProxy } from './network/proxy'
|
||||||
import { needsLegacyMigration, migrateFromLegacyDir, ensureAppDirs } from './paths'
|
import { needsLegacyMigration, migrateFromLegacyDir, ensureAppDirs } from './paths'
|
||||||
@@ -207,6 +207,11 @@ class MainProcess {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
app.isQuiting = true
|
app.isQuiting = true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 退出前清理资源
|
||||||
|
app.on('will-quit', () => {
|
||||||
|
cleanup()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ function clearTempDbCache(filePath: string): void {
|
|||||||
/**
|
/**
|
||||||
* 清理所有缓存(删除所有临时数据库)
|
* 清理所有缓存(删除所有临时数据库)
|
||||||
*/
|
*/
|
||||||
function clearAllTempDbCache(): void {
|
export function cleanupTempDbs(): void {
|
||||||
for (const tempDbPath of tempDbCache.values()) {
|
for (const tempDbPath of tempDbCache.values()) {
|
||||||
deleteTempDatabase(tempDbPath)
|
deleteTempDatabase(tempDbPath)
|
||||||
}
|
}
|
||||||
@@ -125,9 +125,8 @@ export function registerMergeHandlers(ctx: IpcContext): void {
|
|||||||
if (filePath) {
|
if (filePath) {
|
||||||
clearTempDbCache(filePath)
|
clearTempDbCache(filePath)
|
||||||
} else {
|
} else {
|
||||||
clearAllTempDbCache()
|
cleanupTempDbs()
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import type { IpcContext } from './ipc/types'
|
|||||||
// 导入各功能模块
|
// 导入各功能模块
|
||||||
import { registerWindowHandlers } from './ipc/window'
|
import { registerWindowHandlers } from './ipc/window'
|
||||||
import { registerChatHandlers } from './ipc/chat'
|
import { registerChatHandlers } from './ipc/chat'
|
||||||
import { registerMergeHandlers, initMergeModule } from './ipc/merge'
|
import { registerMergeHandlers, initMergeModule, cleanupTempDbs } from './ipc/merge'
|
||||||
import { registerAIHandlers } from './ipc/ai'
|
import { registerAIHandlers } from './ipc/ai'
|
||||||
import { registerMessagesHandlers } from './ipc/messages'
|
import { registerMessagesHandlers } from './ipc/messages'
|
||||||
import { registerCacheHandlers } from './ipc/cache'
|
import { registerCacheHandlers } from './ipc/cache'
|
||||||
@@ -50,4 +50,16 @@ const mainIpcMain = (win: BrowserWindow) => {
|
|||||||
console.log('[IpcMain] All IPC handlers registered successfully')
|
console.log('[IpcMain] All IPC handlers registered successfully')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const cleanup = () => {
|
||||||
|
console.log('[IpcMain] Cleaning up resources...')
|
||||||
|
try {
|
||||||
|
// 关闭 Worker
|
||||||
|
worker.closeWorker()
|
||||||
|
// 清理临时数据库
|
||||||
|
cleanupTempDbs()
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[IpcMain] Error during cleanup:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default mainIpcMain
|
export default mainIpcMain
|
||||||
|
|||||||
Reference in New Issue
Block a user