I am trying to send information from my react code (through ipcRenderer) to my index.electron.js file (listening on ipcMain), but the message is not being picked up.
The exact flow is:
- Send message from
mainWindow.webContents - Execute some react code
- Send message from react code back to electron
- Electron listens to the message and executes a zoomFactor change
My code is as follows:
index.electron.js:
const ipcMain = require('electron').ipcMain;
...
click: () => mainWindow.webContents.send('TEST-1', 'message sent from mainWindow') // this works
...
ipcMain.on('TEST-2', (event, arg) => { // this does not work
console.log('IPC MAIN', arg);
});
some-react-component.js
ipcRenderer.on('TEST-1', (event, message) => { // this works
console.log('react-component', message);
ipcRenderer.send('TEST-2', 'message sent from react');
});
ipcRenderer.on('TEST-2', (event, message) => { // this works (this is just to check if TEST-2 is sending
console.log('react-component', message);
});
The ipcRenderer is picking up the message sent on channels TEST-1 and TEST-2, but I cannot get the ipcMain to listen on TEST-2
Thanks :)