Skip to content

Commit

Permalink
Merge pull request #2 from Kastakin/win_process
Browse files Browse the repository at this point in the history
Kill all related process when exiting
  • Loading branch information
jhk0530 authored Jan 18, 2024
2 parents 72071a7 + 8846199 commit dd45de7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion [fix] package-json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"axios": "0.27.2",
"electron-squirrel-startup": "^1.0.0",
"esm": "^3.2.25",
"execa": "^5.1.1"
"execa": "^5.1.1",
"pidtree": "^0.6.0"
},
"devDependencies": {
"@babel/core": "^7.22.20",
Expand Down
18 changes: 12 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import path from 'path'
import http from 'axios'
import os from 'os'
import execa from 'execa'
import pidtree from 'pidtree';
import {
randomPort,
waitFor,
Expand Down Expand Up @@ -83,10 +84,10 @@ const tryStartWebserver = async (attempt, progressCallback, onErrorStartup, onEr
'R_LIBS_SITE': libPath,
'R_LIB_PATHS': libPath
}
}).catch((e) => {
shinyProcessAlreadyDead = true
onError(e)
})
});
pidtree(rShinyProcess.pid, function (err, pids) {
child_pids = pids;
});

let url = `http://127.0.0.1:${shinyPort}`
for (let i = 0; i <= 50; i++) {
Expand Down Expand Up @@ -225,6 +226,11 @@ app.on('window-all-closed', () => {
shutdown = true
app.quit()
try {
rShinyProcess.kill()
} catch (e) {}
rShinyProcess.kill();
child_pids.forEach((pid) => {
try {
process.kill(pid, "SIGTERM");
} catch (e) {}
});
} catch (e) {}
})

0 comments on commit dd45de7

Please sign in to comment.