From 83150eea88709221099310a148271d4aa77accbe Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Sat, 11 Oct 2025 11:39:57 +0530 Subject: [PATCH] Fix double-click file opening with did-finish-load event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added did-finish-load event listener to ensure window is fully loaded - Added 500ms delay to allow TabManager initialization - Improved openFileFromPath function with better logging - Fixed race condition where files opened via double-click weren't rendering Fixes #file-association-rendering-issue 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/main.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main.js b/src/main.js index 8c7c664..73415fa 100644 --- a/src/main.js +++ b/src/main.js @@ -83,7 +83,18 @@ function createWindow() { mainWindow = null; }); - // Handle pending file from file association will be handled by renderer-ready event + // Wait for the page to fully load before sending file data + mainWindow.webContents.on('did-finish-load', () => { + console.log('Window finished loading'); + // Give renderer a moment to initialize + setTimeout(() => { + if (app.pendingFile && !rendererReady) { + console.log('Opening pending file after did-finish-load:', app.pendingFile); + openFileFromPath(app.pendingFile); + app.pendingFile = null; + } + }, 500); // Wait 500ms for TabManager to initialize + }); } function buildRecentFilesMenu() { @@ -1552,14 +1563,15 @@ function openFileFromPath(filePath) { currentFile = filePath; const content = fs.readFileSync(filePath, 'utf-8'); if (mainWindow && mainWindow.webContents) { - // Wait for the renderer to be ready (TabManager initialized) before sending file data - if (rendererReady) { - mainWindow.webContents.send('file-opened', { path: filePath, content }); - } else { - // Store file to open after renderer is ready - app.pendingFile = filePath; - } + console.log('Attempting to open file:', filePath, 'rendererReady:', rendererReady); + // Always try to send, the renderer will handle it when ready + mainWindow.webContents.send('file-opened', { path: filePath, content }); + } else { + // Store file to open after window is created + app.pendingFile = filePath; } + } else { + console.error('File does not exist:', filePath); } }