Use ipcRenderer.sendTo to get rid of routers in main process

This commit is contained in:
Cheng Zhao 2016-05-28 21:13:00 +09:00
parent a58b84bbd7
commit ba315248e0
5 changed files with 33 additions and 50 deletions

View file

@ -352,12 +352,16 @@ ipcMain.on('ELECTRON_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', function (event, request
}
})
ipcMain.on('ELECTRON_BROWSER_SEND_TO', function (event, webContentsId, channel, ...args) {
ipcMain.on('ELECTRON_BROWSER_SEND_TO', function (event, sendToAll, webContentsId, channel, ...args) {
let contents = webContents.fromId(webContentsId)
if (!contents) {
console.error(`Sending message to WebContents with unknown ID ${webContentsId}`)
return
}
contents.send(channel, ...args)
if (sendToAll) {
contents.sendToAll(channel, ...args)
} else {
contents.send(channel, ...args)
}
})