Skip to content

Commit

Permalink
🐛 修复退出后frp仍在运行的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
luckjiawei committed Dec 1, 2023
1 parent f5df6bb commit 4c12c80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion electron/api/frpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,17 @@ export const reloadFrpcProcess = () => {
/**
* 停止frpc子进程
*/
export const stopFrpcProcess = () => {
export const stopFrpcProcess = (callback?:() => void) => {
if (frpcProcess) {
treeKill(frpcProcess.pid, (error: Error) => {
if (error) {
console.log("关闭失败", frpcProcess.pid, error)
} else {
console.log('关闭成功')
frpcProcess = null
clearInterval(frpcStatusListener)
}
callback()
})
}
}
Expand Down
11 changes: 8 additions & 3 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ export const createTray = () => {
label: '退出',
click: () => {
isQuiting = true;
app.quit();
stopFrpcProcess(() => {
app.quit();
})
}
}
];
Expand All @@ -143,8 +145,11 @@ app.whenReady().then(() => {

app.on("window-all-closed", () => {
win = null;
if (process.platform !== "darwin") app.quit();
stopFrpcProcess()
if (process.platform !== "darwin") {
stopFrpcProcess(() => {
app.quit();
})
}
});

app.on("second-instance", () => {
Expand Down

0 comments on commit 4c12c80

Please sign in to comment.