-
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(); // 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 void
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
let argument: { threadID: string, message: string } = /* something */;
let result: string = await ipcRenderer.invoke("send-message", argument);
// 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 void
let argument: { name?: string, tagline?: string } = /* something */;
await ipcRenderer.invoke("set-group-info", argument); // returns void