惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
Vercel News
Vercel News
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
量子位
Engineering at Meta
Engineering at Meta
B
Blog RSS Feed
博客园 - 【当耐特】
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
人人都是产品经理
人人都是产品经理
IT之家
IT之家
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
博客园 - 三生石上(FineUI控件)

Show HN

GitHub - astefanutti/shaderbang: Shebang for Shaders Show HN: Generate Claude Code Workflows using Spec Driven Development approach Show HN: AI agents for UK GDAD PCF roles and their skills The Two Pillars: Mixer Mode and Meta-Software in the Reorganization of Software Work After AI GitHub - JaiCode08/teleport-env What 1,000+ Harness Experiments Taught Me About Self-Improving Agents Show HN: Liiists, a Markdown-first, iOS and CLI list app SwiperTab – Get this Extension for 🦊 Firefox (en-US) GitHub - kouhxp/fftext: Summarize, explain, fact-check, or translate any text, URL, or file. No GPU. No cloud. One command GitHub - sweetpad-dev/sweetpad: Develop Swift/iOS projects using VSCode GitHub - dogmaticdev/IRON: IRON a.k.a. Intermediate Representation Object Notation is a Interpreter/Database that is used to create Programming Languages. GitHub - sjhalani7/vaen: Package your AI coding harness into a portable .agent file, and share it across repos, teams, & the community without ever having to copy-paste instructions, skills, MCP config, or secrets. Show HN: Gandalf the Grader Show HN: Citadeld – replay any CI failure locally from a single file GitHub - tdortman/cuSBF: High-Performance GPU Super Bloom Filter coral-ai/claude-code-token-xray at main · Coral-Bricks-AI/coral-ai GitHub - ulyssestenn/funes: Funes is a Git-based framework for LLM-managed knowledge work: an AI Librarian ingests raw sources, builds an interlinked Markdown knowledge base, and uses it to produce cited reports, analyses, and other outputs. GitHub - ThatXliner/gah: Git Add Hunk, built for agents to use GitHub - harmont-dev/harmont-cli: Command-line client for the Harmont CI platform GitHub - brooksmcmillin/mcp-authflow: OAuth 2.0 Authorization Server framework for MCP servers GitHub - javaid-codes/audit-supply-chain-agents GitHub - amorey/gochan: A small library of common channel architectures for Go, inspired by Rust GitHub - arifozgun/OpenGem: Free, Open-Source AI API Gateway with Gemini, OpenAI & Anthropic Compatibility in 1 file GitHub - Pranesh950/BioPetals: 🌸 Run BIOxAI models at home, BitTorrent-style. Fine-tuning and inference up to 10x faster than offloading GitHub - cnguyen14/bounty-doctor: Diagnose a GitHub bounty issue before you waste hours: detects honeypot scam repos, AI-bot attempt swarms, and stale contests. Show HN: CoreMCP – MCP Server for On-Prem DBs Show HN: KittyHTML – Render HTML/CSS as an inline image in your terminal GitHub - bingud/filemat: Web-based file manager Show HN: TruthLens – Free multi-signal deepfake image detector GitHub - apexlocal-jz/claude-usage-tray: Windows system-tray app showing your Claude Code rate-limit usage at a glance. Zero deps, ~300 lines of PowerShell. Cross-IDE (works regardless of VS Code, Cursor, plain terminal).
GitHub - johnyrokita/electron-expose: Generate type-safe ...
jskull · 2026-06-19 · via Show HN

NPM Version NPM License NPM Downloads

Generate type-safe Electron IPC bridges from decorated TypeScript functions.

Electron IPC usually means keeping channel names, main handlers, preload bridges, shared types, and renderer calls in sync. electron-expose generates that bridge from the functions you expose in code, so the renderer gets a typed window.api without the repeated wiring.

One goal: make Electron IPC boring.

Why

  • No manual ipcMain.handle(...) and ipcRenderer.invoke(...) pairing
  • No hand-maintained renderer API types
  • No repeating the same method shape across main, preload, and renderer
  • Type-safe window.api.* calls generated from exposed functions

Mark class methods with decorators:

import { expose } from "electron-expose"

export class CalculatorRoutes {
  @expose("math.calculate")
  calculate(a: number, b: number): number {
    return a + b
  }
}

Or expose standalone functions:

import { exposed } from "electron-expose"

export const getVersion = exposed(
  "system.getVersion",
  async (): Promise<string> => {
    return app.getVersion()
  },
)

Then call the generated API from the renderer:

const answer = await window.api.math.calculate(2, 3)
const version = await window.api.system.getVersion()

Install

Quick Start

Initialize the project:

pnpm electron-expose init

Then expose functions in the main process:

import { expose } from "electron-expose"

export class CalculatorRoutes {
  @expose("math.calculate")
  calculate(a: number, b: number): number {
    return a + b
  }
}

Generate the Electron bridge:

pnpm electron-expose generate

To inspect discovered functions without writing generated files:

pnpm electron-expose list

init is interactive. It can create config, patch detected main/preload files, and enable experimentalDecorators in tsconfig.json.

For CI or setup scripts:

pnpm electron-expose init --yes

Plumb It In

Main process:

import { registerElectronExposeRoutes } from "./generated/electron-expose/main"

registerElectronExposeRoutes()

Preload:

import { exposeElectronApi } from "./generated/electron-expose/preload"

exposeElectronApi()

Renderer:

await window.api.math.calculate(2, 3)

Config

Most projects can start with an empty config:

import { defineConfig } from "electron-expose"

export default defineConfig()

Common options:

import { defineConfig } from "electron-expose"

export default defineConfig({
  root: "src",
  outDir: "src/generated/electron-expose",
  globalApiName: "api",
  routePrefix: "electron-expose",
  rendererGlobal: "src/renderer/global.d.ts",
})

By default, electron-expose scans root for *.ts and *.tsx, then only generates bridge entries for @expose() or exposed(...). Generated/build folders, declaration files, and node_modules are ignored automatically.

For custom layouts:

export default defineConfig({
  include: ["packages/main/src/**/*.ts"],
  exclude: ["**/*.spec.ts"],
})

Exposing Functions

Class methods use decorators:

export class UserRoutes {
  @expose("users.get")
  getUser(id: string): Promise<User> {
    return userService.getUser(id)
  }
}

Classes must be exported and currently need a zero-argument constructor. Decorators are used as build-time markers for electron-expose generate; they are not runtime registration logic.

TypeScript does not allow decorators on top-level functions, so standalone functions use exposed(...):

import { exposed } from "electron-expose"

export const ping = exposed("system.ping", (): string => "pong")

Contributing

Issues, bug reports, and focused pull requests are welcome.

Before opening a pull request, run:

pnpm run check
pnpm run build