mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-03 02:11:07 +05:30
fix(ipc): wire preload bridge so menu Open file actually loads in editor + preview
Two related defects were breaking the 'open file' flow: 1. The BrowserWindow webPreferences had no preload path AND contextIsolation: false, so contextBridge.exposeInMainWorld threw on load and window.electronAPI was never set. Result: every renderer-side ipc.* call returned CHANNEL_MISSING and silently no-op'd. Toolbar Open/Save, the file menu, every dialog — all broken. 2. The 'file.opened' IPC bridge in register-menu-commands.ts dispatched to a 'file.opened' command that was never registered as a handler. Even if the preload had worked, the main menu's File -> Open would have been a no-op once it reached the command store. Fixes: - window/index.js: add preload path; set contextIsolation: true (required for contextBridge) and nodeIntegration: false (renderer no longer needs direct Node access; everything goes through the whitelisted preload bridge). - file-store.ts: add openFileFromMain(path, content) that opens a tab + editor buffer from content the main process already read (skips the renderer's ipc.file.read since main has the bytes). Preserves existing buffer content if the file is already open. - register-menu-commands.ts: register 'file.opened' to call openFileFromMain. Drop the dead 'command.palette' bridge (no consumer, no UI, no handler). - tests: two new cases for openFileFromMain — verifies it does not call ipc.file.read and does not clobber user edits on re-open. Verified end-to-end via the run-desktop driver: triggering file-opened from the main process with a test .md now shows the content in BOTH the CodeMirror editor and the rendered preview pane (plus the Outline panel picks up the H1). 497 tests pass.
This commit is contained in:
@@ -102,6 +102,10 @@ export function registerMenuCommands(): void {
|
||||
});
|
||||
register('view.toggleSidebar', () => useAppStore.getState().toggleSidebar());
|
||||
register('view.togglePreview', () => useAppStore.getState().togglePreview());
|
||||
register('file.opened', (payload?: { path?: string; content?: string }) => {
|
||||
if (!payload?.path) return;
|
||||
void useFileStore.getState().openFileFromMain(payload.path, payload.content ?? '');
|
||||
});
|
||||
}
|
||||
|
||||
export function useRegisterMenuCommands(): void {
|
||||
@@ -118,7 +122,6 @@ export function useRegisterMenuCommands(): void {
|
||||
export function useBridgeNativeMenu(): void {
|
||||
useMenuAction('file-save', 'file.save');
|
||||
useMenuAction('toggle-preview', 'view.togglePreview');
|
||||
useMenuAction('toggle-command-palette', 'command.palette');
|
||||
useMenuAction('toggle-sidebar-panel', 'view.sidebarPanel', (panel) => panel as string);
|
||||
useMenuAction('toggle-bottom-panel', 'view.bottomPanel');
|
||||
useMenuAction('toggle-find', 'find.toggle');
|
||||
|
||||
Reference in New Issue
Block a user