Fix double-click file opening with did-finish-load event

- 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)
This commit is contained in:
2025-10-11 11:39:57 +05:30
parent 282af0836c
commit 51baae774d
+20 -8
View File
@@ -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);
}
}