@@ -26,6 +26,9 @@ const cleanupElectronApp = async () => {
2626
2727export const electronGlobalStates : { app ?: ChildProcess } = { }
2828
29+ let cleanupPromise = null
30+ const onExit = async ( ) => cleanupPromise || ( cleanupPromise = cleanupElectronApp ( ) ) // Ensure cleanup is only done once
31+
2932export async function startup ( root ) {
3033
3134 const argv = [ '.' , '--no-sandbox' ]
@@ -45,30 +48,9 @@ export async function startup( root ) {
4548 stdio : [ 'ignore' , 'pipe' , 'pipe' ]
4649 } )
4750
48- // Kill the process after Electron.app exits
49- app . once ( 'exit' , cleanup . exit ) // Calls cleanup and exits the process
50-
51- // Print out any messages from Electron.app
52- app . stdout . on ( 'data' , data => log ( data ) )
53-
54- // Print out any errors from Electron.app
55- app . stderr . on ( 'data' , data => log ( data , 'error' ) )
56-
57- if ( ! startup . hookedProcessExit ) {
58- startup . hookedProcessExit = true
59- process . once ( 'exit' , startup . exit ) // Ensure we clean up when the Node.js process exits
60- }
61-
51+ app . stdout . on ( 'data' , data => log ( data ) ) // Print out any messages from Electron.app
52+ app . stderr . on ( 'data' , data => log ( data , 'error' ) ) // Print out any errors from Electron.app
53+ cleanup . onCleanup ( onExit ) // Kill the process after the process exits
54+
6255 return app
6356 }
64-
65- startup . hookedProcessExit = false
66-
67-
68- // Exit the Electron process and remove all listeners
69- let cleanupPromise = null
70- startup . exit = async ( ) => cleanupPromise || ( cleanupPromise = cleanupElectronApp ( ) ) // Ensure cleanup is only done once
71-
72- // Properly close Electron process on Windows.
73- const signals = [ 'SIGTERM' , 'SIGINT' ]
74- signals . forEach ( signal => process . on ( signal , startup . exit ) )
0 commit comments