# ipc2promise

> 将 electron 的 ipcMain 与 ipcRenderer 间的通信转换为 promise 模式

Latest version **1.1.0** (published 2018-01-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install ipc2promise
pnpm add ipc2promise
yarn add ipc2promise
bun add ipc2promise
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-01-02 |
| First published | 2017-12-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Maintainers | think2011 |

## Links

- npm: https://www.npmjs.com/package/ipc2promise
- Repository: https://github.com/think2011/ipc2promise
- Homepage: https://github.com/think2011/ipc2promise#readme
- Issues: https://github.com/think2011/ipc2promise/issues
- npm.io page: https://npm.io/package/ipc2promise

## Recent versions

- 1.1.0 (latest) — 2018-01-02
- 1.0.0 — 2017-12-08

## README

# ipc2promise
将 electron 的 ipcMain 与 ipcRenderer 间的通信转换为 promise 模式

![](https://raw.github.com/think2011/ipc2promise/master/demo.gif)

## 安装

### npm
```sh
$ npm i ipc2promise
```

## 使用

### 主线程（main process）

```js
const ipc2promise = require('ipc2promise')

ipc2promise.on('download', async (event, data, resolve ,reject) => {
    try {
        resolve(await download(data.url))
    } catch (err) {
        reject(new Error(err))
    }
})
```

### 渲染进程（renderer process）

```js
const ipc2promise = require('ipc2promise')

ipc2promise.send('download', {url: 'https://xxxxxxxx.com/pkg.zip'})
    .then((filePath) => {
        console.log(filePath)
    })
    .catch((err) => {
        console.error('Oops..')
    })
```

## API

### on(event, fn)

- `event`
  - `String` - 事件名
- `fn`
  - `Function(event, data, resolve, reject)` event: event, data: 获得的数据， resolve: 通过， reject: 拒绝

### send(event, data)

- `event`
  - `String` - 事件名
- `data`
  - `*` - 要发送的数据


## License

The MIT license.

---
_Source: https://npm.io/package/ipc2promise · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
