mirror of
https://github.com/alex8088/electron-vite.git
synced 2026-04-30 01:38:14 +08:00
Merge f7162326e294632f56c75bb1ff11a78e75ade0d7 into 31965d29724313f84d505e5ba0e493279a895d7b
This commit is contained in:
commit
94b5295da6
@ -161,5 +161,32 @@ export function startElectron(root: string | undefined): ChildProcess {
|
||||
const ps = spawn(electronPath, [entry].concat(args), { stdio: 'inherit' })
|
||||
ps.on('close', process.exit)
|
||||
|
||||
forwardTerminationSignals(ps)
|
||||
|
||||
return ps
|
||||
}
|
||||
|
||||
let signalHandlersInstalled = false
|
||||
let currentElectronPs: ChildProcess | undefined
|
||||
|
||||
// Forward termination signals to the Electron child, matching electron's own
|
||||
// CLI wrapper (node_modules/electron/cli.js). Without this, Ctrl-C kills the
|
||||
// parent immediately and the Electron child can get stuck on macOS when a
|
||||
// before-quit handler calls preventDefault then later app.quit(). See #899.
|
||||
function forwardTerminationSignals(ps: ChildProcess): void {
|
||||
currentElectronPs = ps
|
||||
if (signalHandlersInstalled) return
|
||||
signalHandlersInstalled = true
|
||||
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP'] as const) {
|
||||
process.on(signal, () => {
|
||||
const target = currentElectronPs
|
||||
if (target && target.exitCode === null && !target.killed) {
|
||||
try {
|
||||
target.kill(signal)
|
||||
} catch {
|
||||
// already gone
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user