npm install promisify-electron-ipc
or
yarn add promisify-electron-ipc
You can find the documentation here.
Sending messages from the renderer to the main process:
// In the main process
import { promiseIpcMain } from "promisify-electron-ipc";
promiseIpcMain.on("greet-channel", name => {
return Promise.resolve("Hello " + name);
});
// In the renderer
import { promiseIpcRenderer } from "promisify-electron-ipc";
promiseIpcRenderer
.send("greet-channel", "Bob")
.then(answer => console.log(answer)); // prints "Hello Bob"
Sending messages from the main process to the renderer:
// In the main process
import { promiseIpcMain } from "promisify-electron-ipc";
promiseIpcMain
.send("greet-channel", win.webContents, "Bob")
.then(answer => console.log(answer));
// In the renderer
import { promiseIpcRenderer } from "promisify-electron-ipc";
promiseIpcRenderer.on("greet-channel", name => {
return Promise.resolve("Hello " + name);
});
This library was inspired by sibnerian