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
This commit is contained in:
Pedram Amini
2026-02-04 11:41:06 -06:00
parent 3109189305
commit a761b84e77

View File

@@ -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