Electron-Anwendungen entwickeln
Implementiert Electron-Funktionen mit isolierten Prozessen, enger geprüfter Kommunikation und vorhersehbarem nativen Verhalten.
electron-development
Agenten mit diesem Skill
Wann ist der Skill hilfreich?
Nutze dies für Dateizugriff oder Hintergrundarbeit aus der Oberfläche.
Wobei hilft er dir?
- Trennt Verantwortungen von Haupt-, Renderer- und Hilfsprozessen.
- Bietet typisierte Preload-Operationen statt uneingeschränktem Node-Zugriff.
- Validiert Nachrichten und behandelt Fenster sowie native Dialoge konsistent.
Das könntest du fragen
Ergänze einen Dateiimport über eine enge Preload-API mit Anfrageprüfung im Hauptprozess. Sende aus dem Renderer einen unerwarteten Pfad und ungültige Anfragestruktur. Der Hauptprozess weist beides ab, der normale native Import funktioniert weiterhin.
Ausführliche Dokumentation
Hier findest du die ursprüngliche Anleitung, Beispiele und Prüfschritte des Skills in ihrer Originalsprache.
Weniger anzeigen
Electron Development
Structure Electron applications around a strict separation of responsibilities: Main Process (OS integration, window lifecycle, IPC gatekeeper), Preload Script (minimal contextBridge surface), Renderer (sandboxed web UI), and utilityProcess (CPU-heavy or embedded Node.js server/worker workloads).
Multi-Process Architecture & utilityProcess
Never block the Electron Main process event loop with synchronous filesystem scans, SQLite queries, or embedded HTTP server request handling—blocking Main freezes window dragging, menus, and IPC across the entire app:
// Spawn an embedded Node.js backend or heavy worker via utilityProcess (uses Chromium Services API)
import { utilityProcess, MessageChannelMain } from 'electron';
import path from 'node:path';
const { port1, port2 } = new MessageChannelMain();
const serverProc = utilityProcess.fork(path.join(__dirname, 'server-entry.js'), [], {
env: { ...process.env, APP_USER_DATA: app.getPath('userData') },
stdio: 'pipe',
serviceName: 'local-backend',
});
serverProc.postMessage({ type: 'init' }, [port1]);
Typed contextBridge & Validated ipcMain.handle
- Preload (
preload.ts):- Pass only serializable data and narrow functions across
contextBridge.exposeInMainWorld('desktopApi', { ... }). - Never pass raw
ipcRenderer.oncallbacks that leak theIpcRendererEventobject; wrap listeners and return an explicitunsubscribe()function so React/Vue/Angular components can clean up on unmount.
- Pass only serializable data and narrow functions across
- Main Process (
ipcMain.handle):- Always check
event.senderFrame?.originagainst the expected app origin before executing privileged operations. - Return structured result objects (
{ ok: true, data } | { ok: false, code, message }) rather than relying on unhandled Error serialization, which strips custom properties across IPC.
- Always check
Window State, Native Dialogs & OS Polish
- Prevent visual flash on launch: Create
BrowserWindowwithshow: falseand a matchingbackgroundColor, then show it insidewin.once('ready-to-show', () => win.show()). - Persist and validate window bounds: Save
{ x, y, width, height, isMaximized }on resize/move (debounced), and on startup verify viascreen.getDisplayMatching(bounds)that the saved coordinates still intersect an attached monitor (handling unplugged external displays gracefully). - Parent-attached native dialogs: Always pass the active
BrowserWindowreference as the first argument todialog.showOpenDialog(win, ...)/dialog.showMessageBox(win, ...)so sheets attach properly on macOS and modal z-order is respected on Windows. - Custom protocol & deep links (
app.setAsDefaultProtocolClient):- On macOS, handle incoming
myapp://URLs viaapp.on('open-url', (event, url) => ...). - On Windows/Linux, extract the URL from
process.argvon initial launch and insideapp.on('second-instance', (event, commandLine) => ...), validating the URL structure strictly before routing.
- On macOS, handle incoming
Enthaltene Dateien 1
SKILL.md
