Promise tron
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/
Install
npm install promise-tron --save
or
git clone https://github.com/thomaschampagne/promise-tron
cd promise-tron
npm install
npm run build
Usage
Message from ipcRenderer to ipcMain
import { BrowserWindow, ipcMain, ipcRenderer } from "electron";
import { PromiseTron } from "promise-tron";
const promiseTronRenderer = new PromiseTron(ipcRenderer);
promiseTronRenderer.send('Hi from renderer!').then(response => {
console.log(response);
}, error => {
console.error(error);
});
const browserWindow = new BrowserWindow();
const promiseTronMain = new PromiseTron(ipcMain, browserWindow.webContents);
promiseTronMain.on((request , replyWith ) => {
console.log(request.data);
replyWith({
success: 'Reply from ipcMain',
error: null
});
});
Message from ipcMain to ipcRenderer
import { BrowserWindow, ipcMain, ipcRenderer } from 'electron'
import { PromiseTron } from 'promise-tron'
const browserWindow = new BrowserWindow();
const promiseTronMain = new PromiseTron(ipcMain, browserWindow.webContents);
promiseTronMain.send('Hi from main!').then(response => {
console.log(response);
}, error => {
console.error(error);
});
const promiseTronRenderer = new PromiseTron(ipcRenderer);
promiseTronRenderer.on((request , replyWith ) => {
console.log(request.data);
replyWith({
success: 'Reply from ipcRenderer',
error: null
});
});
NPM scripts
npm test
: Run test suitenpm start
: Run npm 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 :wink:)