Skip to content

A type-safe library for strict typing to Electron's IPC modules

Notifications You must be signed in to change notification settings

waltcow/iron-ipc

Repository files navigation

iron-ipc

Module for type-safe inter process communication (IPC) in electron.

Installation

yarn add iron-ipc

Usage

create custom ipc module

import * as electron from 'electron';
import { IronIpcMain, IronIpcRenderer } from 'iron-ipc';

export const enum Channel {
    addTodos: "addTodos";
    removeTodos: "removeTodos";
}

interface IpcChannelMap {
  [Channel.addTodos]: {
      id: number,
      title: string,
      content: string
  };
  [Channel.removeTodos]: number
}

const ipcRenderer: IronIpcRenderer<IpcChannelMap> = electron.ipcRenderer;
const ipcMain: IronIpcMain<IpcChannelMap> = electron.ipcMain;

export { ipcMain, ipcRenderer };

use it in renderer or main process

import { ipcMain, Channel } from "shard/ipc"

ipcMain.on(Channel.addTodos, (event, payload) => {
    let title = payload.title
    ...
});

About

A type-safe library for strict typing to Electron's IPC modules

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published