修复部分问题

This commit is contained in:
1600822305 2025-04-11 03:53:14 +08:00
parent 1f967765e4
commit 644995dd76
2 changed files with 35 additions and 0 deletions

View File

@ -3,10 +3,12 @@ import { replaceDevtoolsFont } from '@main/utils/windowUtil'
import { IpcChannel } from '@shared/IpcChannel'
import { app, ipcMain } from 'electron'
import installExtension, { REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS } from 'electron-devtools-installer'
import Logger from 'electron-log'
import { registerIpc } from './ipc'
import { configManager } from './services/ConfigManager'
import { registerMsTTSIpcHandlers } from './services/MsTTSIpcHandler'
import mcpService from './services/MCPService'
import { CHERRY_STUDIO_PROTOCOL, handleProtocolUrl, registerProtocolClient } from './services/ProtocolClient'
import { registerShortcuts } from './services/ShortcutService'
import { TrayService } from './services/TrayService'
@ -96,6 +98,15 @@ if (!app.requestSingleInstanceLock()) {
app.isQuitting = true
})
app.on('will-quit', async () => {
// event.preventDefault()
try {
await mcpService.cleanup()
} catch (error) {
Logger.error('Error cleaning up MCP service:', error)
}
})
// In this file you can include the rest of your app"s specific main process
// code. You can also put them in separate files and require them here.
}

View File

@ -322,6 +322,30 @@ class McpService {
// 转换回字符串
return Array.from(existingPaths).join(pathSeparator)
}
/**
* MCP客户端连接
*/
public async cleanup(): Promise<void> {
Logger.info('[MCP] Cleaning up all MCP clients...')
const closePromises: Promise<void>[] = []
// 关闭所有客户端连接
for (const [serverKey, client] of this.clients.entries()) {
try {
Logger.info(`[MCP] Closing client for server: ${serverKey}`)
closePromises.push(client.close())
} catch (error) {
Logger.error(`[MCP] Error closing client for server: ${serverKey}`, error)
} finally {
this.clients.delete(serverKey)
}
}
// 等待所有关闭操作完成
await Promise.allSettled(closePromises)
Logger.info('[MCP] All MCP clients cleaned up')
}
}
export default new McpService()