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

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');
2020-03-20 20:28:31 +00:00
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();