From a761b84e7709574e6631ad6f4d4efe70fb2fff31 Mon Sep 17 00:00:00 2001 From: Pedram Amini Date: Wed, 4 Feb 2026 11:41:06 -0600 Subject: [PATCH] Ensure dialog:selectFolder IPC handler always sends reply Add try-catch wrapper and isDestroyed() check to prevent "reply was never sent" errors when the window closes during dialog operations. Fixes MAESTRO-58 --- src/main/ipc/handlers/system.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/ipc/handlers/system.ts b/src/main/ipc/handlers/system.ts index d61a4654..0e6b6470 100644 --- a/src/main/ipc/handlers/system.ts +++ b/src/main/ipc/handlers/system.ts @@ -61,20 +61,29 @@ export function registerSystemHandlers(deps: SystemHandlerDependencies): void { // ============ Dialog Handlers ============ // Folder selection dialog + // Wrapped in try-catch to ensure a reply is always sent, even if the window + // is closed while the dialog is open or other unexpected errors occur. + // Fixes MAESTRO-58: "reply was never sent" ipcMain.handle('dialog:selectFolder', async () => { - const mainWindow = getMainWindow(); - if (!mainWindow) return null; + try { + const mainWindow = getMainWindow(); + if (!mainWindow || mainWindow.isDestroyed()) return null; - const result = await dialog.showOpenDialog(mainWindow, { - properties: ['openDirectory', 'createDirectory'], - title: 'Select Working Directory', - }); + const result = await dialog.showOpenDialog(mainWindow, { + properties: ['openDirectory', 'createDirectory'], + title: 'Select Working Directory', + }); - if (result.canceled || result.filePaths.length === 0) { + if (result.canceled || result.filePaths.length === 0) { + return null; + } + + return result.filePaths[0]; + } catch (error) { + // Log the error but return null to ensure IPC reply is sent + logger.error('dialog:selectFolder failed', 'Dialog', { error }); return null; } - - return result.filePaths[0]; }); // File save dialog