PromiseTron is a promise based communication system library which simplify data exchange between electron main and renderer processes.
PromiseTron includes typescript definitions.
Api doc: https://thomaschampagne.github.io/promise-tron/
npm install promise-tron --save
or
git clone https://github.com/thomaschampagne/promise-tron
cd promise-tron
npm install
npm run build
import { BrowserWindow, ipcMain, ipcRenderer } from "electron";
import { PromiseTron } from "promise-tron";
// Renderer
const promiseTronRenderer = new PromiseTron(ipcRenderer);
promiseTronRenderer.send('Hi from renderer!').then(response => {
console.log(response); // Prints: "Reply from ipcMain"
}, error => {
console.error(error);
});
// Main
const browserWindow = new BrowserWindow();
const promiseTronMain = new PromiseTron(ipcMain, browserWindow.webContents);
promiseTronMain.on((request /*IpcRequest*/, replyWith /*(promiseTronReply: PromiseTronReply) => void*/) => {
console.log(request.data); // Prints: "Hi from renderer!"
replyWith({
success: 'Reply from ipcMain',
error: null
});
});
import { BrowserWindow, ipcMain, ipcRenderer } from 'electron'
import { PromiseTron } from 'promise-tron'
// Main
const browserWindow = new BrowserWindow();
const promiseTronMain = new PromiseTron(ipcMain, browserWindow.webContents);
promiseTronMain.send('Hi from main!').then(response => {
console.log(response); // Prints: "Reply from ipcRenderer"
}, error => {
console.error(error);
});
// Renderer
const promiseTronRenderer = new PromiseTron(ipcRenderer);
promiseTronRenderer.on((request /*IpcRequest*/, replyWith /*(promiseTronReply: PromiseTronReply) => void*/) => {
console.log(request.data); // Prints: "Hi from main!"
replyWith({
success: 'Reply from ipcRenderer',
error: null
});
});
npm test
: Run test suitenpm start
: Runnpm run build
in watch modenpm run test:watch
: Run test suite in interactive watch modenpm run test:prod
: Run linting and generate coveragenpm run build
: Generate bundles and typings, create docsnpm run lint
: Lints codenpm run commit
: Commit using conventional commit style (husky will tell you to use it if you haven't 😉)