From f85c1a8107a2ac3c91bb52c00f58ee61466e2bac Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Mon, 8 Jun 2026 06:20:59 +0530 Subject: [PATCH] feat(preload): allowlist updater:* and crash:* channels, expose API --- src/preload.js | 32 +++++++++++++++++++++++++++++++- src/renderer/lib/ipc.ts | 22 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/preload.js b/src/preload.js index b532f30..3d14a51 100644 --- a/src/preload.js +++ b/src/preload.js @@ -135,6 +135,16 @@ const ALLOWED_SEND_CHANNELS = [ 'app:open-external', 'app:show-save-dialog', + // Updater + 'updater:check', + 'updater:install', + 'updater:get-state', + + // Crash reporter + 'crash:read', + 'crash:open-dir', + 'crash:delete', + // Git diff 'git-diff', @@ -231,6 +241,9 @@ const ALLOWED_RECEIVE_CHANNELS = [ 'print-preview-styled', 'clear-recent-files', + // Updater + 'updater:status', + // File dialog / directory listing 'list-directory', 'pick-folder', @@ -439,7 +452,24 @@ contextBridge.exposeInMainWorld('electronAPI', { quit: () => ipcRenderer.send('app:quit'), openExternal: (url) => ipcRenderer.send('app:open-external', url), showSaveDialog: (args) => ipcRenderer.invoke('app:show-save-dialog', args), - } + }, + + updater: { + check: () => ipcRenderer.invoke('updater:check'), + install: () => ipcRenderer.invoke('updater:install'), + getState: () => ipcRenderer.invoke('updater:get-state'), + onStatus: (cb) => { + const subscription = (_event, payload) => cb(payload); + ipcRenderer.on('updater:status', subscription); + return () => ipcRenderer.removeListener('updater:status', subscription); + }, + }, + + crash: { + read: () => ipcRenderer.invoke('crash:read'), + openDir: () => ipcRenderer.send('crash:open-dir'), + delete: (filename) => ipcRenderer.invoke('crash:delete', filename), + }, }); // Log successful preload initialization diff --git a/src/renderer/lib/ipc.ts b/src/renderer/lib/ipc.ts index af0db59..c67832f 100644 --- a/src/renderer/lib/ipc.ts +++ b/src/renderer/lib/ipc.ts @@ -117,4 +117,26 @@ export const ipc = { return window.electronAPI.on(channel, callback as (...a: any[]) => void); }, }, + updater: { + check: (): Promise> => + safeCall('updater', 'check'), + install: (): Promise> => + safeCall('updater', 'install'), + getState: (): Promise> => + safeCall('updater', 'getState'), + onStatus: (cb: (payload: unknown) => void): (() => void) => { + if (typeof window === 'undefined' || !window.electronAPI?.updater?.onStatus) { + return () => {}; + } + return window.electronAPI.updater.onStatus(cb); + }, + }, + crash: { + read: (): Promise> => + safeCall('crash', 'read'), + openDir: (): Promise> => + safeCall('crash', 'openDir'), + delete: (filename: string): Promise> => + safeCall('crash', 'delete', filename), + }, }; \ No newline at end of file