From 0a25e19498149a1382126c66aa6d963c7597b9f0 Mon Sep 17 00:00:00 2001 From: hinamiyagk Date: Tue, 29 Dec 2015 01:20:15 +0900 Subject: [PATCH] Add type definition for IPC Event on main process --- github-electron/github-electron-main-tests.ts | 4 ++-- github-electron/github-electron.d.ts | 20 ++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/github-electron/github-electron-main-tests.ts b/github-electron/github-electron-main-tests.ts index 8a0d4125f..55588681f 100644 --- a/github-electron/github-electron-main-tests.ts +++ b/github-electron/github-electron-main-tests.ts @@ -275,12 +275,12 @@ globalShortcut.unregisterAll(); // ipcMain // https://github.com/atom/electron/blob/master/docs/api/ipc-main-process.md -ipcMain.on('asynchronous-message', (event: any, arg: any) => { +ipcMain.on('asynchronous-message', (event: GitHubElectron.IPCMainEvent, arg: any) => { console.log(arg); // prints "ping" event.sender.send('asynchronous-reply', 'pong'); }); -ipcMain.on('synchronous-message', (event: any, arg: any) => { +ipcMain.on('synchronous-message', (event: GitHubElectron.IPCMainEvent, arg: any) => { console.log(arg); // prints "ping" event.returnValue = 'pong'; }); diff --git a/github-electron/github-electron.d.ts b/github-electron/github-electron.d.ts index 37dd60222..0c11ee048 100644 --- a/github-electron/github-electron.d.ts +++ b/github-electron/github-electron.d.ts @@ -1464,6 +1464,24 @@ declare module GitHubElectron { sendToHost(channel: string, ...args: any[]): void; } + class IPCMain implements NodeJS.EventEmitter { + addListener(event: string, listener: Function): IPCMain; + once(event: string, listener: Function): IPCMain; + removeListener(event: string, listener: Function): IPCMain; + removeAllListeners(event?: string): IPCMain; + setMaxListeners(n: number): IPCMain; + getMaxListeners(): number; + listeners(event: string): Function[]; + emit(event: string, ...args: any[]): boolean; + listenerCount(type: string): number; + on(event: string, listener: (event: IPCMainEvent, ...args: any[]) => any): IPCMain; + } + + interface IPCMainEvent { + returnValue?: any; + sender: WebContents; + } + interface Remote extends CommonElectron { /** * @returns The object returned by require(module) in the main process. @@ -1761,7 +1779,7 @@ declare module GitHubElectron { BrowserWindow: typeof GitHubElectron.BrowserWindow; contentTracing: GitHubElectron.ContentTracing; dialog: GitHubElectron.Dialog; - ipcMain: NodeJS.EventEmitter; + ipcMain: GitHubElectron.IPCMain; globalShortcut: GitHubElectron.GlobalShortcut; Menu: typeof GitHubElectron.Menu; MenuItem: typeof GitHubElectron.MenuItem;