In the electron main.js I am wanting to send an event from a child Window to a mainWindow. The way I thought to do this was by sending an event from childWindow to the Main Process, and the Main Process then sends an event to the mainWindow.
ipcMain.on('submit-form-data', (event, data) => {
if (data) {
console.log('send data to main window')
mainWindow.webContents.send('submitted-form', data)
}
childWindow.hide();
})
The childWindow successfully send it's form data to the main process. But when I want the main process to then send that data to the mainWindow, the event is not being picked up. I don't have an idea of what I can try to get this to work.
index.html in the mainWindow
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Main Window</title>
<script>
var ipcRenderer = nodeRequire("electron").ipcRenderer;
ipcRenderer.on("submitted-form", function (event, data) {
alert('received data'); // this never gets called :(
});
</script>