refactor: ensure IpcRenderer is not bridgable (#40330)
* refactor: ensure IpcRenderer is not bridgable * chore: add notes to breaking-changes * spec: fix test that bridged ipcrenderer
This commit is contained in:
parent
39d36e4462
commit
83892ab995
5 changed files with 59 additions and 43 deletions
|
@ -4,20 +4,22 @@ const { ipc } = process._linkedBinding('electron_renderer_ipc');
|
|||
|
||||
const internal = true;
|
||||
|
||||
export const ipcRendererInternal = new EventEmitter() as any as ElectronInternal.IpcRendererInternal;
|
||||
|
||||
ipcRendererInternal.send = function (channel, ...args) {
|
||||
return ipc.send(internal, channel, args);
|
||||
};
|
||||
|
||||
ipcRendererInternal.sendSync = function (channel, ...args) {
|
||||
return ipc.sendSync(internal, channel, args);
|
||||
};
|
||||
|
||||
ipcRendererInternal.invoke = async function<T> (channel: string, ...args: any[]) {
|
||||
const { error, result } = await ipc.invoke<T>(internal, channel, args);
|
||||
if (error) {
|
||||
throw new Error(`Error invoking remote method '${channel}': ${error}`);
|
||||
class IpcRendererInternal extends EventEmitter implements ElectronInternal.IpcRendererInternal {
|
||||
send (channel: string, ...args: any[]) {
|
||||
return ipc.send(internal, channel, args);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
sendSync (channel: string, ...args: any[]) {
|
||||
return ipc.sendSync(internal, channel, args);
|
||||
}
|
||||
|
||||
async invoke<T> (channel: string, ...args: any[]) {
|
||||
const { error, result } = await ipc.invoke<T>(internal, channel, args);
|
||||
if (error) {
|
||||
throw new Error(`Error invoking remote method '${channel}': ${error}`);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
export const ipcRendererInternal = new IpcRendererInternal();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue