-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.js
More file actions
37 lines (33 loc) · 1 KB
/
launch.js
File metadata and controls
37 lines (33 loc) · 1 KB
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
36
37
const { spawn, execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const electronPath = require('electron');
const env = { ...process.env };
delete env.ELECTRON_RUN_AS_NODE;
const pidFile = path.join(__dirname, '.trim-dev.pid');
// Kill any existing instance (entire process tree) before launching
try {
const raw = fs.readFileSync(pidFile, 'utf-8').trim();
const oldPid = Number(raw);
if (Number.isFinite(oldPid) && oldPid > 0) {
if (process.platform === 'win32') {
try { execSync(`taskkill /F /T /PID ${oldPid}`, { stdio: 'ignore' }); } catch {}
} else {
try { process.kill(-oldPid, 'SIGKILL'); } catch {
try { process.kill(oldPid, 'SIGKILL'); } catch {}
};
}
}
} catch {}
try { fs.unlinkSync(pidFile); } catch {}
const child = spawn(electronPath, ['.'], {
cwd: __dirname,
env,
stdio: 'ignore',
detached: true,
});
try {
fs.writeFileSync(pidFile, String(child.pid), 'utf-8');
} catch {}
child.unref();
process.exit(0);