Add comprehensive debugging logging for file loading and print issues

- Added console.log statements throughout file loading flow
- Traces: command-line args → pendingFile → renderer-ready → openFileFromPath → file-opened
- Added logging to print-preview handlers
- Added logging to theme-changed and renderer-ready
- Enabled DevTools automatically for debugging
- Backup renderer-ready timeout (100ms) in case theme-changed doesn't fire
This debugging build will help identify exactly where the flow breaks.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
This commit is contained in:
2025-10-26 20:45:24 +05:30
parent 80bf533483
commit 2999882318
2 changed files with 32 additions and 1 deletions
+17
View File
@@ -112,6 +112,9 @@ function createWindow() {
mainWindow.loadFile(path.join(__dirname, 'index.html'));
// Open DevTools for debugging
mainWindow.webContents.openDevTools();
createMenu();
mainWindow.on('closed', () => {
@@ -1179,8 +1182,11 @@ ipcMain.on('do-print', (event, { withStyles }) => {
// Handle renderer ready for file association
ipcMain.on('renderer-ready', (event) => {
console.log('[MAIN] renderer-ready received, rendererReady was:', rendererReady);
rendererReady = true;
console.log('[MAIN] app.pendingFile:', app.pendingFile);
if (app.pendingFile) {
console.log('[MAIN] Opening pending file:', app.pendingFile);
openFileFromPath(app.pendingFile);
app.pendingFile = null;
}
@@ -1583,13 +1589,17 @@ app.whenReady().then(() => {
// Handle file association on app startup
// Process all command line arguments except the first two (node and script path)
const fileArgs = process.argv.slice(2);
console.log('[MAIN] Command line args:', process.argv);
console.log('[MAIN] File args to process:', fileArgs);
for (const arg of fileArgs) {
if ((arg.endsWith('.md') || arg.endsWith('.markdown')) && fs.existsSync(arg)) {
// Store the file to open after window is ready
console.log('[MAIN] Setting pendingFile to:', arg);
app.pendingFile = arg;
break;
}
}
console.log('[MAIN] Final app.pendingFile:', app.pendingFile);
});
app.on('window-all-closed', () => {
@@ -1641,16 +1651,23 @@ app.on('open-file', (event, filePath) => {
// Handle file opening from command line or file association
function openFileFromPath(filePath) {
console.log('[MAIN] openFileFromPath called with:', filePath);
console.log('[MAIN] rendererReady:', rendererReady, 'mainWindow exists:', !!mainWindow);
if (fs.existsSync(filePath)) {
currentFile = filePath;
const content = fs.readFileSync(filePath, 'utf-8');
console.log('[MAIN] File read successfully, content length:', content.length);
if (mainWindow && mainWindow.webContents && rendererReady) {
// Send file immediately - renderer-ready means UI is initialized
console.log('[MAIN] Sending file-opened to renderer');
mainWindow.webContents.send('file-opened', { path: filePath, content });
} else {
// Store file to open after renderer is ready
console.log('[MAIN] Storing as pending file');
app.pendingFile = filePath;
}
} else {
console.error('[MAIN] File does not exist:', filePath);
}
}
+15 -1
View File
@@ -1039,9 +1039,16 @@ document.addEventListener('DOMContentLoaded', () => {
});
}
// Request current theme - renderer-ready will be sent after theme is applied
// Request current theme
ipcRenderer.send('get-theme');
// Also send renderer-ready immediately as backup
// This ensures we don't get stuck waiting for theme-changed
setTimeout(() => {
console.log('Backup renderer-ready timeout triggered');
ipcRenderer.send('renderer-ready');
}, 100);
// Set up auto-save interval
setInterval(() => {
// Auto-save logic for all tabs
@@ -1059,8 +1066,11 @@ ipcRenderer.on('file-new', () => {
});
ipcRenderer.on('file-opened', (event, data) => {
console.log('[RENDERER] file-opened received:', data.path, 'content length:', data.content.length);
if (tabManager) {
tabManager.openFile(data.path, data.content);
} else {
console.error('[RENDERER] tabManager not initialized!');
}
});
@@ -1098,11 +1108,13 @@ ipcRenderer.on('toggle-find', () => {
});
ipcRenderer.on('theme-changed', (event, theme) => {
console.log('[RENDERER] Theme changed to:', theme);
document.body.className = `theme-${theme}`;
// After theme is applied, wait for next frame then signal renderer is ready
// This ensures complete UI initialization before files are opened
requestAnimationFrame(() => {
console.log('[RENDERER] Sending renderer-ready from theme-changed');
ipcRenderer.send('renderer-ready');
});
});
@@ -1154,10 +1166,12 @@ ipcRenderer.on('adjust-font-size', (event, action) => {
// Print preview request handlers - handle printing directly
ipcRenderer.on('print-preview', () => {
console.log('[RENDERER] print-preview received');
handlePrintPreview(false);
});
ipcRenderer.on('print-preview-styled', () => {
console.log('[RENDERER] print-preview-styled received');
handlePrintPreview(true);
});