-
Notifications
You must be signed in to change notification settings - Fork 0
IPC API
Trevor Sears edited this page Feb 23, 2020
·
5 revisions
To register the various IPC handlers (the API, effectively) after each program start, just import registerHandlers from main/api/ipc-handler and call it:
import { registerHandlers } from "main/api/ipc-handler";
registerHandlers(window.webContents); // Handlers are now ready to go.For each 'method' available over the IPC (inter-process communication), there is a 'function name', a parameter type, and a return type. Note that the return type is always promisified (the resolved value of a Promise). In effect, using a given 'function' on the main process's IPC API would look something like:
let argument: ParameterType = /* something */;
// Calling "function-name" on the main process.
let result: ReturnType = await ipcRenderer.invoke("function-name", argument);Listening for an event from the main process in the renderer process would look something like:
ipcRenderer.on("event-name", (eventInfo: EventInfoType): any => { /* Do stuff */ });// Not yet written
let argument: unknown = /* something */;
await ipcRenderer.invoke("sign-up", argument); // returns voidThis must be done before calling any of the below commands.
let argument: { username: string, password: string } = /* something */;
await ipcRenderer.invoke("sign-in", argument); // returns voidlet argument: { threadID: string, message: string } = /* something */;
let result: Message = await ipcRenderer.invoke("send-message", argument);Typings for Message here.
// Not yet written
let argument: unknown = /* something */;
let result: unknown = await ipcRenderer.invoke("new-conversation", argument);let argument: string = /* something */;
let result: string[] = await ipcRenderer.invoke("search-users", argument);let argument: { filePath: string } = /* something */;
await ipcRenderer.invoke("set-user-avatar", argument); // returns voidlet argument: { name?: string, tagline?: string } = /* something */;
await ipcRenderer.invoke("set-group-info", argument); // returns voidipcRenderer.on("new-message", (message: Message): any => {
// handle new message
});Typings for Message here.
ipcRenderer.on("group-info-changed", (info: { threadID: string, name: string, tagline: string }): any => {
// handle group info changes
});