electron-api
FeaturedGuide for adding new Electron APIs to Wave Terminal. Use when implementing new frontend-to-electron communications via preload/IPC.
Web & Frontend 22,715 stars
1196 forks Updated 4 days ago Apache-2.0
Install
Quality Score: 93/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
Skill Content
# Adding Electron APIs
Electron APIs allow the frontend to call Electron main process functionality directly via IPC.
## Four Files to Edit
1. [`frontend/types/custom.d.ts`](frontend/types/custom.d.ts) - TypeScript [`ElectronApi`](frontend/types/custom.d.ts:82) type
2. [`emain/preload.ts`](emain/preload.ts) - Expose method via `contextBridge`
3. [`emain/emain-ipc.ts`](emain/emain-ipc.ts) - Implement IPC handler
4. [`frontend/preview/preview-electron-api.ts`](frontend/preview/preview-electron-api.ts) - Add a no-op stub to keep the `previewElectronApi` object in sync with the `ElectronApi` type
## Three Communication Patterns
1. **Sync** - `ipcRenderer.sendSync()` + `ipcMain.on()` + `event.returnValue = ...`
2. **Async** - `ipcRenderer.invoke()` + `ipcMain.handle()`
3. **Fire-and-forget** - `ipcRenderer.send()` + `ipcMain.on()`
## Example: Async Method
### 1. Define TypeScript Interface
In [`frontend/types/custom.d.ts`](frontend/types/custom.d.ts):
```typescript
type ElectronApi = {
captureScreenshot: (rect: Electron.Rectangle) => Promise<string>; // capture-screenshot
};
```
### 2. Expose in Preload
In [`emain/preload.ts`](emain/preload.ts):
```typescript
contextBridge.exposeInMainWorld("api", {
captureScreenshot: (rect: Rectangle) => ipcRenderer.invoke("capture-screenshot", rect),
});
```
### 3. Implement Handler
In [`emain/emain-ipc.ts`](emain/emain-ipc.ts):
```typescript
electron.ipcMain.handle("capture-screenshot", async (event, rect) => {
const ...
Details
- Author
- wavetermdev
- Repository
- wavetermdev/waveterm
- Created
- 4 years ago
- Last Updated
- 4 days ago
- Language
- Go
- License
- Apache-2.0
Similar Skills
Semantically similar based on skill content — not just same category
AI & Automation Listed
electron-api
Guide for adding new Electron APIs to Wave Terminal. Use when implementing new frontend-to-electron communications via preload/IPC.
42 Updated 5 months ago
mits-pl Web & Frontend Listed
electron-dev
Electron desktop apps with React, TypeScript, and Vite. Use for IPC, window/tray, PTY terminals, WebRTC, and packaging.
457 Updated 6 days ago
jamditis AI & Automation Listed
electron-main-preload-generator
Generate secure main process and preload script boilerplate with proper context isolation, IPC patterns, and security best practices for Electron applications
1,919 Updated 2 weeks ago
a5c-ai