diff --git a/src/electron/types/TypedIpcMain.ts b/src/electron/types/TypedIpcMain.ts new file mode 100644 index 00000000..c2783755 --- /dev/null +++ b/src/electron/types/TypedIpcMain.ts @@ -0,0 +1,86 @@ +/* To following types are part of electron-typed-ipc, written by Andrei Canta (deiucanta) + * The package is no longer maintained which causes dependency issues. Therefore, we copied the type declaration to this file + * The original package can be found here: https://github.com/deiucanta/electron-typed-ipc + */ + +import { + IpcMain, + IpcMainEvent, + IpcMainInvokeEvent, + IpcRenderer, + IpcRendererEvent, + WebContents +} from 'electron'; + +type OptionalPromise = T | Promise; +type InputMap = { + [key: string]: (...args: any) => any; +}; + +export interface TypedIpcMain + extends IpcMain { + on( + channel: K, + listener: (event: IpcMainEvent, ...args: Parameters) => void + ): this; + once( + channel: K, + listener: (event: IpcMainEvent, ...args: Parameters) => void + ): this; + removeListener( + channel: K, + listener: (event: IpcMainEvent, ...args: Parameters) => void + ): this; + removeAllListeners(channel?: K): this; + handle( + channel: K, + listener: ( + event: IpcMainInvokeEvent, + ...args: Parameters + ) => OptionalPromise> + ): void; + handleOnce( + channel: K, + listener: ( + event: IpcMainInvokeEvent, + ...args: Parameters + ) => OptionalPromise> + ): void; + removeHandler(channel: K): void; +} + +export interface TypedIpcRenderer + extends IpcRenderer { + on( + channel: K, + listener: (event: IpcRendererEvent, ...args: Parameters) => void + ): this; + once( + channel: K, + listener: (event: IpcRendererEvent, ...args: Parameters) => void + ): this; + removeListener( + channel: K, + listener: (event: IpcRendererEvent, ...args: Parameters) => void + ): this; + removeAllListeners(channel: K): this; + send(channel: K, ...args: Parameters): void; + sendSync( + channel: K, + ...args: Parameters + ): ReturnType; + sendTo( + webContentsId: number, + channel: K, + ...args: Parameters + ): void; + sendToHost(channel: K, ...args: Parameters): void; + invoke( + channel: K, + ...args: Parameters + ): Promise>; +} + +export interface TypedWebContents extends WebContents { + send(channel: K, ...args: Parameters): void; +}