mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-09-21 22:45:20 +00:00
fix wrong Id being passed - needed browser id, not webcontent id
This commit is contained in:
@@ -69,28 +69,29 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
/// <param name="channel">Channelname.</param>
|
||||
/// <param name="listener">Callback Method.</param>
|
||||
public void OnWithId(string channel, Action<int, object> listener)
|
||||
public void OnWithId(string channel, Action<(int browserId, int webContentId, object arguments)> listener)
|
||||
{
|
||||
BridgeConnector.Emit("registerIpcMainChannelWithId", channel);
|
||||
BridgeConnector.Off(channel);
|
||||
BridgeConnector.On<ArgsAndId>(channel, (data) =>
|
||||
BridgeConnector.On<ArgsAndIds>(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; }
|
||||
}
|
||||
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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] });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user