electron/lib/renderer/ipc-renderer-internal.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
743 B
TypeScript
Raw Normal View History

2020-06-02 09:33:06 +00:00
import { EventEmitter } from 'events';
const { ipc } = process._linkedBinding('electron_renderer_ipc');
const internal = true;
class IpcRendererInternal extends EventEmitter implements ElectronInternal.IpcRendererInternal {
send (channel: string, ...args: any[]) {
return ipc.send(internal, channel, args);
}
sendSync (channel: string, ...args: any[]) {
return ipc.sendSync(internal, channel, args);
}
2020-06-02 09:33:06 +00:00
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;
};
}
2020-06-02 09:33:06 +00:00
export const ipcRendererInternal = new IpcRendererInternal();