Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/2o3t/electron-ipc-promise
An electron IPC calls with a promise API.
https://github.com/2o3t/electron-ipc-promise
electron electron-ipc-promise ipc listener promise
Last synced: 5 days ago
JSON representation
An electron IPC calls with a promise API.
- Host: GitHub
- URL: https://github.com/2o3t/electron-ipc-promise
- Owner: 2o3t
- Created: 2019-05-30T12:16:46.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-06-24T14:25:28.000Z (over 5 years ago)
- Last Synced: 2024-10-10T20:13:15.054Z (about 1 month ago)
- Topics: electron, electron-ipc-promise, ipc, listener, promise
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# @2o3t/electron-ipc-promise
## Installation
```sh
yarn add @2o3t/electron-ipc-promise
```## Usage
```js
// in main process
const promiseIpc = require('@2o3t/electron-ipc-promise');promiseIpc.on('notify', (newSettings) => {
console.log(newSettings);
return 'test';
});// in renderer
const promiseIpc = require('@2o3t/electron-ipc-promise');promiseIpc
.send('notify', { "name": "Jeff" }')
.then(() => console.log('You wrote the settings!'))
.catch((e) => console.error(e));
```You can also send data from the main process to a renderer, if you pass in its WebContents object.
```js
// in main process
const promiseIpc = require('@2o3t/electron-ipc-promise');promiseIpc
.send('getRendererData', webContentsForRenderer)
.then((rendererData) => console.log(rendererData))
.catch((e) => console.error(e));// in renderer
const promiseIpc = require('@2o3t/electron-ipc-promise');promiseIpc.on('getRendererData', () => {
return getSomeSuperAwesomeRendererData();
});
```### Removing Listeners
You can remove a listener with the off() method.
```js
const promiseIpc = require('@2o3t/electron-ipc-promise');promiseIpc.on('someRoute', () => {
return something();
});promiseIpc.off('someRoute'); // never mind
```