UNPKG

1.46 kBTypeScriptView Raw
1import type { IpcMain, IpcRenderer, WebContents, IpcMainEvent, IpcRendererEvent } from 'electron';
2import 'object.entries/auto';
3declare type IpcEvent = IpcRendererEvent & IpcMainEvent;
4/**
5 * For backwards compatibility, event is the (optional) LAST argument to a listener function.
6 * This leads to the following verbose overload type for a listener function.
7 */
8export declare type Listener = {
9 (event?: IpcEvent): void;
10} | {
11 (arg1?: unknown, event?: IpcEvent): void;
12} | {
13 (arg1?: unknown, arg2?: unknown, event?: IpcEvent): void;
14} | {
15 (arg1?: unknown, arg2?: unknown, arg3?: unknown, event?: IpcEvent): void;
16} | {
17 (arg1?: unknown, arg2?: unknown, arg3?: unknown, arg4?: unknown, event?: IpcEvent): void;
18} | {
19 (arg1?: unknown, arg2?: unknown, arg3?: unknown, arg4?: unknown, arg5?: unknown, event?: IpcEvent): void;
20};
21export declare type Options = {
22 maxTimeoutMs?: number;
23};
24export default class PromiseIpcBase {
25 private eventEmitter;
26 private maxTimeoutMs;
27 private routeListenerMap;
28 private listenerMap;
29 constructor(opts: {
30 maxTimeoutMs?: number;
31 } | undefined, eventEmitter: IpcMain | IpcRenderer);
32 send(route: string, sender: WebContents | IpcRenderer, ...dataArgs: unknown[]): Promise<unknown>;
33 on(route: string, listener: Listener): PromiseIpcBase;
34 off(route: string, listener?: Listener): void;
35 removeListener(route: string, listener?: Listener): void;
36}
37export {};