Reputation: 536
I know how to send events from renderer process to main process using ipcRenderer.send()
and ipcMain.on()
. I could also send reply back to renderer process using event.sender.send()
but got stuck on how can I send events from main process to all renderer process, more like a broadcast.
Upvotes: 3
Views: 2131
Reputation: 1914
You can create array of references to BrowserWindow instances and when global event is necessary you can map it with sender function, like this for example:
let windows = [];
let backgroundComputation = new BrowserWindow(options);
let webInteractions = new BrowserWindow(different_options);
let imageProcessing = new BrowserWindow(another_options);
windows.push(backgroundComputation)
windows.push(webInteractions)
windows.push(imageProcessing)
let sender = (message, windows) =>
windows.map((ref) => ref.webContents.send('event_name', message))
This will probably be handy if you have whole bunch of them. You can also set flag in options alwaysOnTop:true
to true for window on top so any other window will stay underneath. Hope this helps!
Upvotes: 3