Skip to main content

erpc-communication

Guides using eRPC (electron-tRPC) for inter-process communication (IPC) between Electron main and renderer processes. Triggered when handling Electron IPC or tRPC-based systems.

소스 정보

저장소
MatrixAges/polywise
최근 소스 활동
2026년 3월 23일 12:25
감지된 SKILL.md 언어
영어
스타
662
포크
34

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
erpc-communication
description
Guides using eRPC (electron-tRPC) for inter-process communication (IPC) between Electron main and renderer processes. Triggered when handling Electron IPC or tRPC-based systems.
# eRPC Communication Guide This skill provides mandatory instructions for implementing type-safe IPC using eRPC in this project. ## 1. Main Process Implementation - **Route Definition**: Must use the project's provided router utility to define tRPC routes. - **Handler Initialization**: Must use `createIPCHandler` from `erpc/main` to bind the router to Electron windows. - **Context Injection**: Should provide necessary instances (e.g., `BrowserWindow` or `Tray`) through `createContext`. ```typescript // Always initialize createIPCHandler within the app ready lifecycle import { createIPCHandler } from 'erpc/main' import { routers } from './rpcs' createIPCHandler({ createContext: async () => ({ win: mainWindow, tray: appTray }), router: routers, windows: [mainWindow] }) ``` ## 2. Preload Script Configuration - **Expose Bridge Interface**: Must call `exposeElectronTRPC()` provided by `erpc/main` in the preload script. - **Lifecycle**: Should be called inside `process.once('loaded')`. ```typescript import { exposeElectronTRPC } from 'erpc/main' process.once('loaded', () => { exposeElectronTRPC() }) ``` ## 3. Renderer Process Usage - **Client Creation**: Create tRPC client using `ipcLink` from `erpc/renderer`. - **Type Safety**: Always import `Router` type from main process to ensure complete end-to-end type safety. ```typescript import { createTRPCClient } from '@trpc/client' import { ipcLink } from 'erpc/renderer' import type { Router } from '@desktop/rpcs' // Import Router type from main process export const trpc = createTRPCClient<Router>({ links: [ipcLink()] }) ``` ## 4. Routes and Endpoints Best Practices - **Single Responsibility**: Each route should correspond to a specific service in the main process (e.g., `window`, `file`, `dialog`). - **Parameter Validation**: It is strictly prohibited to write complex business logic in Router. Router is only responsible for validating input and output parameters; business logic must be delegated to Service (e.g., calling `WindowService.open()`). - **Type Reference**: For complex object parameters, type definitions must be placed under the `packages/erpc` package and shared between both ends, avoiding direct cross-package imports of entity logic.
GitHub에서 보기