preload.js 568 B

1234567891011121314151617181920212223
  1. const { ipcRenderer, contextBridge } = require('electron')
  2. contextBridge.exposeInMainWorld('api', {
  3. doAction: async (arg) => {
  4. return await ipcRenderer.invoke('main', arg)
  5. },
  6. checkForUpdates: async (...args) => {
  7. await ipcRenderer.invoke('check-for-updates', ...args)
  8. },
  9. setUpdatesCallback (cb) {
  10. if (typeof cb !== 'function') return
  11. const channel = 'updates-callback'
  12. ipcRenderer.removeAllListeners(channel)
  13. ipcRenderer.on(channel, cb)
  14. },
  15. installUpdatesAndQuitApp () {
  16. ipcRenderer.invoke('install-updates', true)
  17. }
  18. })