Skip to content

Commit 8e7b859

Browse files
committed
kill backend explicitly with kill -9 command on Unix either on clicking cross or via quit
1 parent 23122d3 commit 8e7b859

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

cleanup.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
const isWindows = process.platform === 'win32';
1+
const os = require('os');
2+
const platform = os.platform();
23

34
const kill = (process) => {
45
console.log(`Attempting to kill process with PID: ${process.pid}`);
5-
if (isWindows) {
6-
const { spawn } = require('child_process');
6+
const { spawn } = require('child_process');
7+
if (platform === 'win32') {
78
// used taskkill for Windows to terminate the process tree
89
const taskKill = spawn('taskkill', ['/PID', process.pid, '/T', '/F']);
910
taskKill.on('close', (code) => {
@@ -13,6 +14,15 @@ const kill = (process) => {
1314
console.error(`taskkill failed with exit code: ${code}`);
1415
}
1516
});
17+
} else if (platform === 'darwin' || platform === 'linux') {
18+
const taskKill = spawn('kill', ['-9', process.pid]);
19+
taskKill.on('close', (code) => {
20+
if (code === 0) {
21+
console.log('Process killed successfully on Unix.');
22+
} else {
23+
console.error(`taskkill failed with exit code: ${code}`);
24+
}
25+
});
1626
} else {
1727
try {
1828
process.kill('SIGINT');

main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ app.whenReady().then(() => {
317317
});
318318
});
319319

320-
app.on('window-all-closed', () => {
320+
app.on("before-quit", function () {
321321
kill(serverProcess);
322+
})
323+
324+
app.on('window-all-closed', () => {
322325
if (process.platform !== 'darwin') app.quit();
323326
});

0 commit comments

Comments
 (0)