@@ -129,29 +129,33 @@ export async function startup(argv = ['.', '--no-sandbox']) {
129129 // Exit command after Electron.app exits
130130 process . electronApp . once ( 'exit' , process . exit )
131131
132- if ( ! startup . hookProcessExit ) {
133- startup . hookProcessExit = true
134- process . once ( 'exit' , startup . exit )
132+ if ( ! startup . hookedProcessExit ) {
133+ startup . hookedProcessExit = true
134+ process . once ( 'exit' , ( ) => {
135+ startup . exit ( )
136+ // When the process exits, `tree-kill` does not have enough time to complete execution, so `electronApp` needs to be killed immediately.
137+ process . electronApp . kill ( )
138+ } )
135139 }
136140}
137- startup . hookProcessExit = false
141+ startup . hookedProcessExit = false
138142startup . exit = async ( ) => {
139143 if ( process . electronApp ) {
140144 process . electronApp . removeAllListeners ( )
141145
142- import ( 'tree-kill' )
146+ await import ( 'tree-kill' )
143147 . then ( m => m . default ( process . electronApp . pid ! ) )
144148 . catch ( e => {
149+ process . electronApp . kill ( )
150+
145151 if ( e . code === 'ERR_MODULE_NOT_FOUND' ) {
146152 console . log (
147153 '[vite-plugin-electron]' ,
148- 'install tree-kill to exit all associated processes, place run "npm i tree-kill".' ,
154+ 'Please install tree-kill to exit all associated processes, run "npm i tree-kill -D ".' ,
149155 )
150156 } else {
151157 console . error ( e )
152158 }
153159 } )
154-
155- process . electronApp . kill ( ) // `tree-kill` doesn't work locally on my Mac(2023-11-06) 🤔
156160 }
157161}
0 commit comments