/electron-ipc-extra

:dart: A Better Promise based IPC Library in Electron

Primary LanguageJavaScript

electron-promise-extra

🎯 A Better Promise based IPC Library in Electron

Features

  • Promise based API, write with async / await simply
  • Send a message and get the response back in the same call
  • Same Api in Renderer and Main Process, Electron-compatible api design
  • Always send to all browserWindows from main process, forget the webContents
  • Keep the raw event object just in case
  • Work fine with electron-builder (no peerDependencies limit)

Installation

$ npm install electron-promise-extra --save

Usage

// in renderer or main process
import ipc from 'electron-ipc-extra'

ipc.on('channel-name', async (...args) => {
  await getSomeData()
  return 'reply data'
})
// in main or renderer process
import ipc from 'electron-ipc-extra'

let data = await ipc.send('channel-name', 'some data', 'another data')
console.log('data') // => 'reply data'

Get original event object

ipc.on('ondragstart', async function(...args) {
  var { event } = this
  event.sender.startDrag({
    file: 'some file',
    icon: 'some native image'
  })
  return 'reply data'
})

Removing Listeners

import ipc from 'electron-ipc-extra'

ipc.off('channel-name')

Debug IPC data

Install Devtron

Reference Doc

License

MIT