cleanup on shutdown

This commit is contained in:
pompurin404 2024-09-28 20:10:51 +08:00
parent 1f2eee133b
commit 9f0a18ecce
No known key found for this signature in database
2 changed files with 17 additions and 3 deletions

View File

@ -2,6 +2,7 @@
- Windows 允许添加 `noadmin` 参数以普通权限启动程序
- 支持在 Windows 任务栏显示网速信息
- 支持在关机前自动关闭系统代理
### Bug Fixes

View File

@ -1,7 +1,7 @@
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import { registerIpcMainHandlers } from './utils/ipc'
import windowStateKeeper from 'electron-window-state'
import { app, shell, BrowserWindow, Menu, dialog, Notification } from 'electron'
import { app, shell, BrowserWindow, Menu, dialog, Notification, powerMonitor } from 'electron'
import { addProfileItem, getAppConfig } from './config'
import { quitWithoutCore, startCore, stopCore } from './core/manager'
import { triggerSysProxy } from './sys/sysproxy'
@ -96,9 +96,17 @@ app.on('window-all-closed', (e) => {
// }
})
app.on('before-quit', async () => {
await stopCore()
app.on('before-quit', async (e) => {
e.preventDefault()
triggerSysProxy(false)
await stopCore()
app.exit()
})
powerMonitor.on('shutdown', async (e) => {
e.preventDefault()
triggerSysProxy(false)
await stopCore()
app.exit()
})
@ -239,6 +247,11 @@ export async function createWindow(): Promise<void> {
}
})
mainWindow.on('session-end', async () => {
triggerSysProxy(false)
await stopCore()
})
mainWindow.webContents.setWindowOpenHandler((details) => {
shell.openExternal(details.url)
return { action: 'deny' }