Configures Electron 39 app shell, main process lifecycle, window management, and oRPC-based IPC communication. Use when: creating or modifying main process code, adding IPC handlers, configuring window behavior, setting up auto-updates, working with preload scripts, or packaging/building the app.
This project uses Electron 39 with a frameless window, oRPC over MessagePort for type-safe IPC (not ipcMain.handle), and electron-vite for unified builds. The main process lives in src/main.ts, IPC domains in src/ipc/<domain>/, and the renderer is a React 19 app.
Main (src/main.ts) ←── MessagePort (oRPC) ──→ Preload (src/preload.ts) ←── contextBridge ──→ Renderer
| Process | Entry | Has Node.js | Has DOM |
|---|---|---|---|
| Main | src/main.ts | Yes | No |
| Preload | src/preload.ts | Limited | Yes |
| Renderer |
src/renderer.ts |
| No |
| Yes |
Every domain follows: schema → handler → barrel → router → action.
// 1. src/ipc/checklist/schemas.ts
import z from "zod";
export const readFileInputSchema = z.object({ path: z.string() });
// 2. src/ipc/checklist/handlers.ts
import { os } from "@orpc/server";
import { readFileInputSchema } from "./schemas";
export const readChecklistFile = os
.input(readFileInputSchema)
.handler(async ({ input }) => {
/* Node.js file I/O here */
});
// 3. src/ipc/checklist/index.ts
export const checklist = { readChecklistFile };
// 4. src/ipc/router.ts — add to router object
import { checklist } from "./checklist";
export const router = { theme, window, app, shell, updater, checklist };
// 5. src/actions/checklist.ts — renderer wrapper
import { ipc } from "@/ipc/manager";
export async function readChecklistFile(path: string) {
return ipc.client.checklist.readChecklistFile({ path });
}
| Concept | Location | Notes |
|---|---|---|
| Window creation | src/main.ts:createWindow() | Frameless, context isolation, platform title bar |
| oRPC setup | src/main.ts:setupORPC() | Receives MessagePort, upgrades to RPC handler |
| IPC context | src/ipc/context.ts | Singleton providing BrowserWindow to handlers |
| Auto-updater | src/main.ts:setupAutoUpdater() | GitHub Releases, private repo token support |
| Constants | src/constants/index.ts | IPC_CHANNELS, UPDATE_CHANNELS |
| Build config | electron.vite.config.ts | Three targets: main, preload, renderer |
| Package config | electron-builder.yml | ASAR, Fuses, NSIS/ZIP/DEB+RPM |
Use the ipcContext.mainWindowContext middleware:
import { os } from "@orpc/server";
import { ipcContext } from "@/ipc/context";
export const myHandler = os
.use(ipcContext.mainWindowContext)
.handler(({ context }) => {
const { window } = context; // BrowserWindow instance
window.minimize();
});
Fetch latest Electron documentation with Context7.
How to use Context7:
mcp__context7__resolve-library-id to search for "electron"/websites/electronjs) over source codemcp__context7__query-docs using the resolved library IDLibrary ID: /websites/electronjs
Recommended Queries: