Reputation: 468
So I'm building an app using the Electron framework and trying to pass some data between a parent window and a child window as I open the child window on a click event from the parent. I'm using ipcMain and ipcRenderer to pass a message from the parent renderer process, to the main process, to the child renderer process. I can track the data coming to the main process however it doesn't get sent to the final renderer. I'm not really quite sure why, but my intuition is that it has something to do with the coordination of events of opening the child window from main vs sending data via .webContents.send() from main.
Relevant code:
Sending data from the parent to main
listItem.click(function(){
ipcRenderer.send('synchronous-message',feedUrl);
})
Listening in main for the data, initializing and opening the child window, and sending the data to the child window
let winPodInfo;
ipcMain.on('synchronous-message',(event,arg)=>{
winPodInfo = new BrowserWindow({
width:500,
parent:mainWindow,
modal:true,
frame:false
});
winPodInfo.loadURL(`file://${__dirname}/podcastInfo.html`);
winPodInfo.once('show',function(){
winPodInfo.webContents.send('synchronous-message',arg);
})
winPodInfo.once('ready-to-show', () => {
winPodInfo.show();
});
})
Checking for the message in the child renderer
<script>
const electron = require('electron');
const {ipcRenderer} = electron;
ipcRenderer.on('synchronous-message',(event,arg)=>{
console.log(arg);
})
</script>
I know that this question has been asked on here before, and I've looked at the other examples but so far they haven't worked.
Upvotes: 1
Views: 6615
Reputation: 1325
The Window.on('show')
event does not trigger until you set show: false
in window options.
winPodInfo = new BrowserWindow({
show: false
});
winPodInfo.once("show", function() {
winPodInfo.webContents.send("channel", arg);
});
winPodInfo.once("ready-to-show", () => {
winPodInfo.show();
});
Upvotes: 2