0.6.1 • Published 8 days ago

electron-trpc v0.6.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 days ago

electron-trpc

Build IPC for Electron with tRPC

  • Expose APIs from Electron's main process to one or more render processes.
  • Build fully type-safe IPC.
  • Secure alternative to opening servers on localhost.
  • Subscription support coming soon.

Installation

# Using pnpm
pnpm add electron-trpc

# Using yarn
yarn add electron-trpc

# Using npm
npm install --save electron-trpc

Setup

  1. Add your tRPC router to the Electron main process using createIPCHandler:

    import { app, ipcMain } from 'electron';
    import { createIPCHandler } from 'electron-trpc';
    import { router, createContext } from './api';
    
    app.on('ready', () => {
      createIPCHandler({ ipcMain, router, createContext }));
    
      // ...
    });
  2. Expose the IPC to the render process from the preload file:

    import { contextBridge, ipcRenderer } from 'electron';
    import { exposeElectronTRPC } from 'electron-trpc';
    
    process.once('loaded', async () => {
      exposeElectronTRPC({ contextBridge, ipcRenderer });
    });

    Note: electron-trpc depends on contextIsolation being enabled, which is the default.

  3. When creating the client in the render process, use the ipcLink (instead of the HTTP or batch HTTP links):

    import * as trpc from '@trpc/client';
    import { ipcLink } from 'electron-trpc';
    
    export const trpcClient = trpc.createTRPCClient({
      links: [ipcLink()],
    });
  4. Now you can use the client in your render process as you normally would (e.g. using @trpc/react).

0.6.1

8 days ago

0.6.0

8 days ago

0.5.2

11 months ago

0.5.1

11 months ago

0.4.5

1 year ago

0.4.4

1 year ago

0.5.0

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.3.0

1 year ago

0.4.1

1 year ago

0.3.2

1 year ago

0.4.0

1 year ago

0.3.1

1 year ago

0.2.0-next.3

2 years ago

0.2.0-next.2

2 years ago

0.2.0-next.1

2 years ago

0.2.0-next.0

2 years ago

0.2.1

1 year ago

0.2.0

1 year ago

0.2.0-next.7

2 years ago

0.2.0-next.6

2 years ago

0.2.0-next.5

2 years ago

0.2.0-next.4

2 years ago

0.1.0

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago