mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 12:56:46 +08:00
Update ipc-main + ipc-renderer modules
This commit is contained in:
@@ -16,9 +16,11 @@ import * as fs from 'fs';
|
||||
// https://github.com/atom/electron/blob/master/docs/api/ipc-renderer.md
|
||||
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong"
|
||||
|
||||
ipcRenderer.on('asynchronous-reply', (arg: any) => {
|
||||
ipcRenderer.on('asynchronous-reply', (event: Electron.IpcRendererEvent, arg: any) => {
|
||||
console.log(arg); // prints "pong"
|
||||
event.sender.send('another-message', 'Hello World!');
|
||||
});
|
||||
|
||||
ipcRenderer.send('asynchronous-message', 'ping');
|
||||
|
||||
// remote
|
||||
|
||||
21
github-electron/github-electron.ipc-main.d.ts
vendored
21
github-electron/github-electron.ipc-main.d.ts
vendored
@@ -7,13 +7,30 @@
|
||||
/// <reference path="github-electron.web-contents.d.ts" />
|
||||
|
||||
declare namespace Electron {
|
||||
|
||||
/**
|
||||
* The ipcMain module handles asynchronous and synchronous messages
|
||||
* sent from a renderer process (web page).
|
||||
* Messages sent from a renderer will be emitted to this module.
|
||||
*/
|
||||
class IpcMain extends EventEmitter {
|
||||
on(event: string, listener: (event: IpcMainEvent, ...args: any[]) => any): this;
|
||||
addListener(channel: string, listener: IpcMainEventListener): this;
|
||||
on(channel: string, listener: IpcMainEventListener): this;
|
||||
once(channel: string, listener: IpcMainEventListener): this;
|
||||
removeListener(channel: string, listener: IpcMainEventListener): this;
|
||||
removeAllListeners(channel?: string): this;
|
||||
}
|
||||
|
||||
type IpcMainEventListener = (event: IpcMainEvent, ...args: any[]) => void;
|
||||
|
||||
interface IpcMainEvent {
|
||||
/**
|
||||
* Set this to the value to be returned in a synchronous message.
|
||||
*/
|
||||
returnValue?: any;
|
||||
/**
|
||||
* Returns the webContents that sent the message, you can call sender.send
|
||||
* to reply to the asynchronous message.
|
||||
*/
|
||||
sender: WebContents;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,17 @@
|
||||
/// <reference path="github-electron.event-emitter.d.ts" />
|
||||
|
||||
declare namespace Electron {
|
||||
|
||||
/**
|
||||
* The ipcRenderer module provides a few methods so you can send synchronous
|
||||
* and asynchronous messages from the render process (web page) to the main process.
|
||||
* You can also receive replies from the main process.
|
||||
*/
|
||||
class IpcRenderer extends EventEmitter {
|
||||
addListener(channel: string, listener: IpcRendererEventListener): this;
|
||||
on(channel: string, listener: IpcRendererEventListener): this;
|
||||
once(channel: string, listener: IpcRendererEventListener): this;
|
||||
removeListener(channel: string, listener: IpcRendererEventListener): this;
|
||||
removeAllListeners(channel?: string): this;
|
||||
/**
|
||||
* Send ...args to the renderer via channel in asynchronous message, the main
|
||||
* process can handle it by listening to the channel event of ipc module.
|
||||
@@ -21,11 +30,20 @@ declare namespace Electron {
|
||||
* message would block the whole renderer process.
|
||||
* @returns The result sent from the main process.
|
||||
*/
|
||||
sendSync(channel: string, ...args: any[]): string;
|
||||
sendSync(channel: string, ...args: any[]): any;
|
||||
/**
|
||||
* Like ipc.send but the message will be sent to the host page instead of the main process.
|
||||
* This is mainly used by the page in <webview> to communicate with host page.
|
||||
*/
|
||||
sendToHost(channel: string, ...args: any[]): void;
|
||||
}
|
||||
|
||||
type IpcRendererEventListener = (event: IpcRendererEvent, ...args: any[]) => void;
|
||||
|
||||
interface IpcRendererEvent {
|
||||
/**
|
||||
* You can call sender.send to reply to the asynchronous message.
|
||||
*/
|
||||
sender: IpcRenderer;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user