-
Notifications
You must be signed in to change notification settings - Fork 0
/
starterWatchdog.js
35 lines (32 loc) · 1.1 KB
/
starterWatchdog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const { spawn } = require('child_process');
const treeKill = require('tree-kill');
const path = require('path');
const { inherits } = require('util');
const electronPath = path.resolve('node_modules', '.bin', 'electron');
// Startet den Electron-Prozess im "detached" Modus
let npmCmd = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
const electronProcess = spawn(npmCmd, ['run', 'normalStart'], {
detached: false,
stdio: 'inherit',
});
let alreadyFinishing = false;
// kill electron process with java subprocess, detecting Ctrl+C in terminal here ^^
electronProcess.on('exit', (code) => {
closeDetected();
});
process.on('SIGINT', (code) => {
closeDetected();
});
function closeDetected() {
if (alreadyFinishing) return;
alreadyFinishing = true;
console.log(`Close detected, will close java processes`);
treeKill(electronProcess.pid, 'SIGKILL', (err) => {
if (err) {
//console.error('Failed to kill process tree:', err); // should be already deleted when this is reached
} else {
console.log('Successfully killed all still running processes.');
process.exit(0);
}
});
}