const { contextBridge, ipcRenderer } = require('electron'); function onIpc(channel, callback) { const listener = (_event, payload) => callback(payload); ipcRenderer.on(channel, listener); return () => ipcRenderer.removeListener(channel, listener); } contextBridge.exposeInMainWorld('electronAPI', { copyToClipboard: (text) => ipcRenderer.invoke('clipboard-write', text), getUpdateState: () => ipcRenderer.invoke('get-update-state'), checkForUpdatesNow: () => ipcRenderer.invoke('check-for-updates-now'), checkForUpdates: () => ipcRenderer.send('check-for-updates'), downloadUpdate: () => ipcRenderer.send('download-update'), quitAndInstall: () => ipcRenderer.send('quit-and-install'), onUpdateState: (callback) => onIpc('update-state', callback), onUpdateAvailable: (callback) => onIpc('update-available', callback), onUpdateDownloaded: (callback) => onIpc('update-downloaded', callback), onUpdateError: (callback) => onIpc('update-error', callback) });