Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thomaschampagne/promise-tron
PromiseTron is a promise based communication system which simplify data exchange between electron main and renderer processes
https://github.com/thomaschampagne/promise-tron
electron ipcmain ipcrenderer promise
Last synced: about 1 month ago
JSON representation
PromiseTron is a promise based communication system which simplify data exchange between electron main and renderer processes
- Host: GitHub
- URL: https://github.com/thomaschampagne/promise-tron
- Owner: thomaschampagne
- License: mit
- Created: 2019-04-20T11:48:00.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2023-04-30T23:47:18.000Z (over 1 year ago)
- Last Synced: 2024-04-11T15:58:05.282Z (9 months ago)
- Topics: electron, ipcmain, ipcrenderer, promise
- Language: TypeScript
- Homepage: https://thomaschampagne.github.io/promise-tron/
- Size: 4.08 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 42
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: code-of-conduct.md
Awesome Lists containing this project
README
# 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/](https://thomaschampagne.github.io/promise-tron/)
## Install
```bash
npm install promise-tron --save
```or
```bash
git clone https://github.com/thomaschampagne/promise-tron
cd promise-tron
npm install
npm run build
```## Usage
### Message from ipcRenderer to ipcMain
```javascript
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
});
});```
### Message from ipcMain to ipcRenderer
```javascript
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 scripts
- `npm test`: Run test suite
- `npm start`: Run `npm run build` in watch mode
- `npm run test:watch`: Run test suite in [interactive watch mode](http://facebook.github.io/jest/docs/cli.html#watch)
- `npm run test:prod`: Run linting and generate coverage
- `npm run build`: Generate bundles and typings, create docs
- `npm run lint`: Lints code
- `npm run commit`: Commit using conventional commit style ([husky](https://github.com/typicode/husky) will tell you to use it if you haven't :wink:)