electron communicate between main and renderer

Solutions on MaxInterview for electron communicate between main and renderer by the best coders in the world

showing results for - "electron communicate between main and renderer"
Eric
20 May 2016
1// In main process.
2const { ipcMain } = require('electron')
3ipcMain.on('asynchronous-message', (event, arg) => {
4  console.log(arg) // prints "ping"
5  event.reply('asynchronous-reply', 'pong')
6})
7
8ipcMain.on('synchronous-message', (event, arg) => {
9  console.log(arg) // prints "ping"
10  event.returnValue = 'pong'
11})
12Copy
Filippo
19 Sep 2018
1// In renderer process (web page).
2const { ipcRenderer } = require('electron')
3console.log(ipcRenderer.sendSync('synchronous-message', 'ping')) // prints "pong"
4
5ipcRenderer.on('asynchronous-reply', (event, arg) => {
6  console.log(arg) // prints "pong"
7})
8ipcRenderer.send('asynchronous-message', 'ping')
9Copy