Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
cleanup on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Sep 28, 2024
1 parent 45ff6d8 commit 2db0833
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

### Bug Fixes

Expand Down
17 changes: 15 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -96,9 +96,17 @@ app.on('window-all-closed', (e) => {
// }
})

app.on('before-quit', async () => {
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()
})

Expand Down Expand Up @@ -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' }
Expand Down

0 comments on commit 2db0833

Please sign in to comment.