diff --git a/ElectronNET.API/IpcMain.cs b/ElectronNET.API/IpcMain.cs index c35efef..a8416ff 100644 --- a/ElectronNET.API/IpcMain.cs +++ b/ElectronNET.API/IpcMain.cs @@ -69,28 +69,29 @@ namespace ElectronNET.API /// /// Channelname. /// Callback Method. - public void OnWithId(string channel, Action listener) + public void OnWithId(string channel, Action<(int browserId, int webContentId, object arguments)> listener) { BridgeConnector.Emit("registerIpcMainChannelWithId", channel); BridgeConnector.Off(channel); - BridgeConnector.On(channel, (data) => + BridgeConnector.On(channel, (data) => { var objectArray = FormatArguments(data.args); if (objectArray.Count == 1) { - listener(data.id, objectArray.First()); + listener((data.id, data.wcId, objectArray.First())); } else { - listener(data.id, objectArray); + listener((data.id, data.wcId, objectArray)); } }); } - private class ArgsAndId + private class ArgsAndIds { public int id { get; set; } + public int wcId { get; set; } public object[] args { get; set; } } diff --git a/ElectronNET.Host/api/ipc.js b/ElectronNET.Host/api/ipc.js index a6f8f13..2f9fc01 100644 --- a/ElectronNET.Host/api/ipc.js +++ b/ElectronNET.Host/api/ipc.js @@ -12,8 +12,10 @@ module.exports = (socket) => { socket.on('registerIpcMainChannelWithId', (channel) => { electron_1.ipcMain.on(channel, (event, args) => { event.preventDefault(); - let id = event.sender.id; - electronSocket.emit(channel, { id: id, args: [args] }); + let wcId = event.sender.id; + let wc = electron_1.webContents.fromId(wcId) + let bw = electron_1.BrowserWindow.fromWebContents(wc); + electronSocket.emit(channel, { id: bw.id, wcId: wcId, args: [args] }); }); }); socket.on('registerSyncIpcMainChannel', (channel) => { diff --git a/ElectronNET.Host/api/ipc.ts b/ElectronNET.Host/api/ipc.ts index 3fe3b41..8927ac9 100644 --- a/ElectronNET.Host/api/ipc.ts +++ b/ElectronNET.Host/api/ipc.ts @@ -1,4 +1,4 @@ -import { ipcMain, BrowserWindow, BrowserView } from 'electron'; +import { ipcMain, BrowserWindow, BrowserView, webContents } from 'electron'; import { Socket } from 'net'; let electronSocket; @@ -14,8 +14,10 @@ export = (socket: Socket) => { socket.on('registerIpcMainChannelWithId', (channel) => { ipcMain.on(channel, (event, args) => { event.preventDefault(); - let id = event.sender.id; - electronSocket.emit(channel, { id: id, args: [args] }); + let wcId = event.sender.id; + let wc = webContents.fromId(wcId) + let bw = BrowserWindow.fromWebContents(wc); + electronSocket.emit(channel, { id: bw.id, args: [args] }); }); });