[READ-ONLY] Mirror of https://github.com/probablykasper/vite-plugin-electron-x. A Vite plugin for bundling main.ts, preload.ts and running Electron in development
0

Configure Feed

Select the types of activity you want to include in your feed.

Fix Electron child process not exiting

Kasper (Feb 21, 2023, 8:28 AM +0100) 5e467ec6 8490b4bf

+16 -10
+3
CHANGELOG.md
··· 1 1 # Changelog 2 2 3 + ## Next 4 + - Fix Electron child process not exiting 5 + 3 6 ## 1.2.1 - 2023 Feb 21 4 7 - Fix RollupWatcher detection error 5 8
+13 -10
src/utils.ts
··· 22 22 process.exit(1) 23 23 } 24 24 25 + let child: ReturnType<typeof spawn> | null = null 26 + function exitChild(signal?: NodeJS.Signals | number) { 27 + if (child) { 28 + child.removeAllListeners() 29 + child.kill(signal) 30 + } 31 + } 32 + 25 33 // Spawn electron, imitates `electron/cli.js` 26 34 export async function spawnElectron(args: string[], env: NodeJS.ProcessEnv) { 27 35 const electronPath = getElectronPath() 28 - const child = spawn(electronPath, args, { stdio: 'inherit', env, windowsHide: false }) 29 - child.on('close', (code, signal) => { 36 + exitChild() 37 + child = spawn(electronPath, args, { stdio: 'inherit', env, windowsHide: false }) 38 + child.on('exit', (code, signal) => { 30 39 if (code === null) { 31 - console.error(electronPath, 'exited with signal', signal) 40 + console.error(electronPath, 'exited with code null and signal', signal) 32 41 process.exit(1) 33 42 } 34 43 process.exit(code) 35 44 }) 36 45 37 - function terminationHandler(signal: NodeJS.Signals) { 38 - if (!child.killed) { 39 - child.kill(signal) 40 - } 41 - } 42 - process.on('SIGINT', terminationHandler) 43 - process.on('SIGTERM', terminationHandler) 46 + process.once('exit', exitChild) 44 47 } 45 48 46 49 export function rmDirIfExists(path: string): Promise<void> {