mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 18:10:18 +05:30
CRITICAL FIX: Print preview and file loading - complete rewrite of timing logic
Print Preview Fix:
- Changed to hide only editor-pane instead of entire editor-container
- Preview was inside editor-container, so hiding it hid the preview too!
- Now correctly shows preview-pane-{tabId} with print-mode class
- Hide all dialogs including find-dialog during print
- Preview now displays correctly for printing
File Loading Fix - Completely Rewritten:
- Root cause: renderer-ready was sent BEFORE theme was applied
- Solution: Moved renderer-ready signal INTO theme-changed handler
- Now waits 1500ms AFTER theme is applied before signaling ready
- Main process delay increased to 500ms for extra safety
- Ensures complete UI render cycle: DOMContentLoaded -> theme request -> theme applied -> wait -> renderer-ready -> file opens
- Files now load and render properly on first double-click
Technical Flow:
1. DOMContentLoaded fires, TabManager initializes
2. get-theme request sent to main
3. theme-changed received, theme applied to body
4. After 1500ms delay, renderer-ready sent
5. Main process waits 500ms more, then sends file-opened
6. Total delay: ~2 seconds ensures rock-solid first-load rendering
🤖 Generated with [Claude Code](https://claude.com/claude-code)
This commit is contained in:
+2
-2
@@ -1669,10 +1669,10 @@ function openFileFromPath(filePath) {
|
||||
const content = fs.readFileSync(filePath, 'utf-8');
|
||||
if (mainWindow && mainWindow.webContents && rendererReady) {
|
||||
// Add delay to ensure renderer is fully prepared to display the file
|
||||
// Increased delay for first-time load when UI is still initializing
|
||||
// Give extra time for theme application and preview pane setup
|
||||
setTimeout(() => {
|
||||
mainWindow.webContents.send('file-opened', { path: filePath, content });
|
||||
}, 300);
|
||||
}, 500);
|
||||
} else {
|
||||
// Store file to open after renderer is ready
|
||||
app.pendingFile = filePath;
|
||||
|
||||
+29
-19
@@ -1039,16 +1039,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
}
|
||||
|
||||
// Request current theme
|
||||
// Request current theme - renderer-ready will be sent after theme is applied
|
||||
ipcRenderer.send('get-theme');
|
||||
|
||||
// Delay renderer-ready signal to ensure all UI initialization completes
|
||||
// This prevents files from opening before the interface is fully loaded
|
||||
// Increased delay to account for slower first-time initialization
|
||||
setTimeout(() => {
|
||||
ipcRenderer.send('renderer-ready');
|
||||
}, 1000);
|
||||
|
||||
// Set up auto-save interval
|
||||
setInterval(() => {
|
||||
// Auto-save logic for all tabs
|
||||
@@ -1106,6 +1099,12 @@ 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
|
||||
// This ensures complete UI initialization before files are opened
|
||||
setTimeout(() => {
|
||||
ipcRenderer.send('renderer-ready');
|
||||
}, 1500);
|
||||
});
|
||||
|
||||
// Undo/Redo handlers
|
||||
@@ -1173,47 +1172,58 @@ ipcRenderer.on('prepare-print-preview', (event, withStyles) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide editor and other UI elements for print
|
||||
document.getElementById('editor-container').style.display = 'none';
|
||||
// Hide UI elements except the preview
|
||||
document.getElementById('toolbar').style.display = 'none';
|
||||
document.getElementById('tab-bar').style.display = 'none';
|
||||
document.getElementById('status-bar').style.display = 'none';
|
||||
|
||||
// Hide editor panes (not the whole editor-container)
|
||||
const editorPane = document.getElementById(`editor-pane-${activeTabId}`);
|
||||
if (editorPane) {
|
||||
editorPane.style.display = 'none';
|
||||
}
|
||||
|
||||
// Hide all export dialogs and other overlays
|
||||
const exportDialog = document.getElementById('export-dialog');
|
||||
const batchDialog = document.getElementById('batch-dialog');
|
||||
const pdfDialog = document.getElementById('pdf-editor-dialog');
|
||||
const converterDialog = document.getElementById('converter-dialog');
|
||||
const findDialog = document.getElementById('find-dialog');
|
||||
if (exportDialog) exportDialog.style.display = 'none';
|
||||
if (batchDialog) batchDialog.style.display = 'none';
|
||||
if (pdfDialog) pdfDialog.style.display = 'none';
|
||||
if (converterDialog) converterDialog.style.display = 'none';
|
||||
if (findDialog) findDialog.style.display = 'none';
|
||||
|
||||
// Show preview in full width
|
||||
const preview = document.getElementById(`preview-${activeTabId}`);
|
||||
if (preview) {
|
||||
preview.classList.add('print-mode');
|
||||
// Make preview full screen for printing
|
||||
const previewPane = document.getElementById(`preview-pane-${activeTabId}`);
|
||||
if (previewPane) {
|
||||
previewPane.classList.add('print-mode');
|
||||
if (!withStyles) {
|
||||
preview.classList.add('print-no-styles');
|
||||
previewPane.classList.add('print-no-styles');
|
||||
}
|
||||
}
|
||||
|
||||
// Re-show everything after print
|
||||
setTimeout(() => {
|
||||
document.getElementById('editor-container').style.display = '';
|
||||
document.getElementById('toolbar').style.display = '';
|
||||
document.getElementById('tab-bar').style.display = '';
|
||||
document.getElementById('status-bar').style.display = '';
|
||||
|
||||
// Restore editor pane
|
||||
if (editorPane) {
|
||||
editorPane.style.display = '';
|
||||
}
|
||||
|
||||
// Restore dialog visibility if they were open
|
||||
if (exportDialog) exportDialog.style.display = '';
|
||||
if (batchDialog) batchDialog.style.display = '';
|
||||
if (pdfDialog) pdfDialog.style.display = '';
|
||||
if (converterDialog) converterDialog.style.display = '';
|
||||
if (findDialog) findDialog.style.display = '';
|
||||
|
||||
const preview = document.getElementById(`preview-${activeTabId}`);
|
||||
if (preview) {
|
||||
preview.classList.remove('print-mode', 'print-no-styles');
|
||||
if (previewPane) {
|
||||
previewPane.classList.remove('print-mode', 'print-no-styles');
|
||||
}
|
||||
}, 500);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user