Answers for "electron communicate between main and renderer"

1

electron communicate between main and renderer

// In main process.
const { ipcMain } = require('electron')
ipcMain.on('asynchronous-message', (event, arg) => {
  console.log(arg) // prints "ping"
  event.reply('asynchronous-reply', 'pong')
})

ipcMain.on('synchronous-message', (event, arg) => {
  console.log(arg) // prints "ping"
  event.returnValue = 'pong'
})
Copy
Posted by: Guest on May-03-2021
1

electron communicate between main and renderer

// In renderer process (web page).
const { ipcRenderer } = require('electron')
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')) // prints "pong"

ipcRenderer.on('asynchronous-reply', (event, arg) => {
  console.log(arg) // prints "pong"
})
ipcRenderer.send('asynchronous-message', 'ping')
Copy
Posted by: Guest on May-03-2021

Code answers related to "electron communicate between main and renderer"

Code answers related to "Javascript"

Browse Popular Code Answers by Language