# electron-typesafe-ipc

> Module for safe inter process communication (IPC) in electron. TypeScript supported.

Latest version **0.0.17** (published 2019-04-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install electron-typesafe-ipc
pnpm add electron-typesafe-ipc
yarn add electron-typesafe-ipc
bun add electron-typesafe-ipc
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.17 |
| Published | 2019-04-02 |
| First published | 2019-03-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 18.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | honzahk |
| Maintainers | honzahk |
| Keywords | electron, ipc, typescript, module, typesafe, type-safe, safe, inter, process, communication, utility |

## Links

- npm: https://www.npmjs.com/package/electron-typesafe-ipc
- Repository: https://github.com/honzahk/electron-typesafe-ipc
- Homepage: https://github.com/honzahk/electron-typesafe-ipc#readme
- Issues: https://github.com/honzahk/electron-typesafe-ipc/issues
- npm.io page: https://npm.io/package/electron-typesafe-ipc

## Dependencies (1)

- [source-map-support](https://npm.io/package/source-map-support.md) ^0.5.10

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.17 (latest) — 2019-04-02
- 0.0.16 — 2019-04-02
- 0.0.15 — 2019-04-02
- 0.0.14 — 2019-03-13
- 0.0.13 — 2019-03-09
- 0.0.12 — 2019-03-09
- 0.0.11 — 2019-03-09
- 0.0.10 — 2019-03-09
- 0.0.9 — 2019-03-09
- 0.0.8 — 2019-03-09
- 0.0.7 — 2019-03-09
- 0.0.6 — 2019-03-09
- 0.0.5 — 2019-03-09
- 0.0.4 — 2019-03-09
- 0.0.3 — 2019-03-09
- … 2 more at https://npm.io/package/electron-typesafe-ipc/versions

## README

# electron-typesafe-ipc

Module for safe inter process communication (IPC) in electron. TypeScript supported.

## Installation

`yarn add electron-typesafe-ipc`

## Usage

configure typesafe ipc object:

```ts
// src/tsipc.ts
import {createIpcChannel, createTypesafeIpc} from "electron-typesafe-ipc";

//first, describe the ipc communication schema - channel names, their direction (main->rend / rend->main) and type of their params (void means no params)
const ipcSchema = {
	main: {
		//main -> rend communication
		trayItemClick: createIpcChannel<{itemId: number}>({msg: "IPC_TRAY_ITEM_CLICK"}),
		trayLogoutClick: createIpcChannel<void>({msg: "IPC_TRAY_LOGOUT_CLICK"})
	},
	rend: {
		//rend -> main communication
		login: createIpcChannel<{loginEmail: string}>({msg: "IPC_LOGIN"}),
		bringWindowToFront: createIpcChannel<void>({msg: "IPC_BRING_TO_FRONT"})
	}
};

//then create the typesafe ipc object via library function
export const tsipc = createTypesafeIpc(ipcSchema);
```

use it in main process:

```ts
// src/main.ts
import {tsipc} from "./tsipc.ts";

//register listener
tsipc.main.on.login(({loginEmail}) => {
	//main process received information that user was logged in via renderer process
	//do whatever you want here - ie change tray menu (display logout button)
});

//send message to renderer process (BrowserWindow win - your app window with target renderer process)
tsipc.main.send.trayLogoutClick(win);
```

use it in renderer process:

```ts
// src/renderer.ts
import {tsipc} from "./tsipc.ts";

//register listener
tsipc.rend.on.trayItemClick(({itemId}) => {
	//renderer process received information that user clicked tray item
	//do whatever you want here
});

//send message to main process
tsipc.rend.send.login({loginEmail: "email@gmail.com"});
```

## API

### configuration

```ts
createIpcChannel<TParamType>({msg: string});
createTypesafeIpc(ipcSchema: TIpcSchema);
```

### usage

```ts
tsipc.main.send;

tsipc.main.on;
tsipc.main.once;
tsipc.main.remove;
```

```ts
tsipc.rend.send;

tsipc.rend.on;
tsipc.rend.once;
tsipc.rend.remove;
```

## Notes

- currently, this library is designed to support only one renderer process (although it may work across many renderer processes, it is not tested)

## TODO

- [ ] app for testing (with webpack)
- [ ] minimal app as an example
- [ ] bi-directional channels (both main->rend and rend->main)
- [ ] document the end-2-end politics (you always register only one event, which distributes the event further)

### sync communication

- [ ] design API
- [ ] implement it (with typesafe return)
- [ ] implement timeout option

### mutliple renderer processes

- [ ] design API to support multiple renderer processes
- [ ] implement API to support multiple renderer processes

### runtime checking

- [ ] check that consumer uses the correct side of tsipc (`tsipc.main.*` in main, `tsipc.rend.*` in renderer)

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