优化
This commit is contained in:
@@ -174,12 +174,41 @@ export function createTray() {
|
||||
{
|
||||
label: '退出应用',
|
||||
click: () => {
|
||||
logger.info('用户点击退出应用')
|
||||
app.isQuiting = true
|
||||
|
||||
// 确保所有窗口都被关闭
|
||||
BrowserWindow.getAllWindows().forEach(window => {
|
||||
window.destroy()
|
||||
const windows = BrowserWindow.getAllWindows()
|
||||
logger.info(`准备关闭 ${windows.length} 个窗口`)
|
||||
|
||||
windows.forEach(window => {
|
||||
if (!window.isDestroyed()) {
|
||||
try {
|
||||
window.destroy()
|
||||
logger.info('窗口销毁成功')
|
||||
} catch (error) {
|
||||
logger.warn('销毁窗口时出错:', error)
|
||||
}
|
||||
}
|
||||
})
|
||||
app.quit()
|
||||
|
||||
// 延迟执行退出,确保窗口销毁完成
|
||||
setTimeout(() => {
|
||||
try {
|
||||
logger.info('执行应用退出')
|
||||
// 使用 exit 而不是 quit,确保完全退出
|
||||
app.exit(0)
|
||||
} catch (error) {
|
||||
logger.error('应用退出失败,尝试强制退出:', error)
|
||||
try {
|
||||
process.exit(0)
|
||||
} catch (processError) {
|
||||
logger.error('强制退出也失败:', processError)
|
||||
// 最后的强制退出
|
||||
process.kill(process.pid, 'SIGKILL')
|
||||
}
|
||||
}
|
||||
}, 500) // 延迟500ms确保窗口销毁完成
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user