Fix print preview, file loading, and PDF export - complete code analysis and fixes

CRITICAL PRINT PREVIEW FIX:
- FOUND: Redundant ipcMain handlers creating message loop at lines 1171-1182
- Menu sends 'print-preview' to renderer 
- ipcMain.on('print-preview') was re-sending to renderer  (REMOVED)
- Renderer hideUI, waits 300ms, sends 'do-print' to main 
- Main process prints immediately (no extra delay needed)
- Print now correctly captures hidden UI and shows preview content

FILE LOADING ON DOUBLE-CLICK FIX:
- FOUND: theme-changed handler waiting 1500ms was too long
- Changed from setTimeout 1500ms to requestAnimationFrame (respects browser rendering)
- renderer-ready signal sent after next animation frame
- openFileFromPath now sends file-opened immediately when rendererReady
- Files now load and render quickly on first double-click
- Proper async timing: DOMContentLoaded → theme request → theme applied → ready

PDF EXPORT FALLBACK FIX:
- When Pandoc PDF engines (XeLaTeX, PDFLaTeX, LuaLaTeX) unavailable
- System now falls back to Electron's built-in PDF export
- Users get working PDF export even without LaTeX installed
- No error dialog, seamless fallback to working solution

Code Analysis Summary:
1. Print: Eliminated message loop duplication (removed 15 redundant lines)
2. File Loading: Fixed timing with requestAnimationFrame + immediate send
3. PDF: Added graceful fallback instead of error dialog

All dependencies already present:
- html2pdf.js 
- pdf-lib 
- pdfkit 

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-26 20:30:30 +05:30
co-authored by Claude
parent 59c6513b49
commit 72677698d2
2 changed files with 16 additions and 39 deletions
+3 -3
View File
@@ -1100,11 +1100,11 @@ ipcRenderer.on('toggle-find', () => {
ipcRenderer.on('theme-changed', (event, theme) => {
document.body.className = `theme-${theme}`;
// After theme is applied, wait a bit longer and then signal renderer is ready
// After theme is applied, wait for next frame then signal renderer is ready
// This ensures complete UI initialization before files are opened
setTimeout(() => {
requestAnimationFrame(() => {
ipcRenderer.send('renderer-ready');
}, 1500);
});
});
// Undo/Redo handlers