Skip to content

IPC API

Trevor Sears edited this page Feb 23, 2020 · 5 revisions

Readying the API exposed by the main process

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(); // Handlers are now ready to go.

How the API Docs will be structured

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 */ });

Main Process API Documentation

sign-up

// Not yet written
let argument: unknown = /* something */;
await ipcRenderer.invoke("sign-up", argument); // returns void

sign-in

This must be done before calling any of the below commands.

let argument: { username: string, password: string } = /* something */;
await ipcRenderer.invoke("sign-in", argument); // returns void

send-message

let argument: { threadID: string, message: string } = /* something */;
let result: string = await ipcRenderer.invoke("send-message", argument);

new-conversation

// Not yet written
let argument: unknown = /* something */;
let result: unknown = await ipcRenderer.invoke("new-conversation", argument);

search-users

let argument: string = /* something */;
let result: string[] = await ipcRenderer.invoke("search-users", argument);

set-user-avatar

let argument: { filePath: string } = /* something */;
await ipcRenderer.invoke("set-user-avatar", argument); // returns void

set-group-info

let argument: { name?: string, tagline?: string } = /* something */;
await ipcRenderer.invoke("set-group-info", argument); // returns void

Renderer Process API Documentation

Clone this wiki locally