@@ -93,7 +93,14 @@ export async function blockQuit(source: string, event?: Electron.Event) {
9393 event . preventDefault ( )
9494 }
9595
96- mainWindow ?. webContents . send ( 'graceful-exit' )
96+ // Only send graceful-exit message if mainWindow is still valid
97+ try {
98+ if ( mainWindow && ! mainWindow . isDestroyed ( ) ) {
99+ mainWindow . webContents . send ( 'graceful-exit' )
100+ }
101+ } catch ( err ) {
102+ log . error ( 'Failed to send graceful-exit message: ' , err )
103+ }
97104
98105 try {
99106 const port = getToolhivePort ( )
@@ -394,6 +401,36 @@ ipcMain.handle('restart-toolhive', async () => {
394401 }
395402} )
396403
404+ ipcMain . handle ( 'install-update-and-restart' , ( ) => {
405+ log . info ( 'Installing update and restarting application' )
406+ // Set a flag to indicate we're installing an update
407+ // This will prevent the graceful shutdown process
408+ isQuitting = true
409+ tearingDown = true
410+
411+ // Stop ToolHive and servers immediately without graceful shutdown
412+ try {
413+ const port = getToolhivePort ( )
414+ if ( port ) {
415+ stopAllServers ( binPath , port ) . catch ( ( err ) => {
416+ log . error ( 'Failed to stop servers during update: ' , err )
417+ } )
418+ }
419+ } catch ( err ) {
420+ log . error ( 'Failed to get port during update: ' , err )
421+ }
422+
423+ // Stop ToolHive
424+ stopToolhive ( )
425+
426+ // Destroy tray
427+ tray ?. destroy ( )
428+
429+ // Install update and restart
430+ autoUpdater . quitAndInstall ( )
431+ return { success : true }
432+ } )
433+
397434// Shutdown store IPC handlers
398435ipcMain . handle ( 'shutdown-store:get-last-servers' , ( ) => {
399436 return getLastShutdownServers ( )
0 commit comments