一键导入
electron-apps
Build secure, production-ready Electron desktop applications with best practices for IPC, CSP, state management, testing, packaging, and auto-updates.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Build secure, production-ready Electron desktop applications with best practices for IPC, CSP, state management, testing, packaging, and auto-updates.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when designing Copilot agents, authoring agent definitions, creating skill folders, or scaffolding instruction files. Provides templates and conventions for the agent ecosystem.
Use when designing, reviewing, or evolving API contracts. Provides OpenAPI templates, breaking-change checklists, versioning decision trees, and governance checklists.
API authentication, authorization, input validation, rate limiting, and protection patterns
Scan legacy applications to discover project structure, NuGet/npm dependencies, database connection strings, external service bindings, framework versions, and migration complexity scores. Produces structured JSON, YAML, or Markdown inventory reports.
Use when designing systems, recording architecture decisions, evaluating technologies, or assessing architectural risks. Provides C4 diagram templates, ADR format, technology selection matrices, and risk registers.
Deploy, scale, and manage containerized applications on Azure Container Apps with Dapr, revision management, and advanced networking
| name | electron-apps |
| description | Build secure, production-ready Electron desktop applications with best practices for IPC, CSP, state management, testing, packaging, and auto-updates. |
| applyTo | agent-electron-developer, agent-desktop-engineer |
| compatibility | ["VS Code","Cursor","Windsurf","Claude Code"] |
| metadata | {"category":"Uncategorized","tags":["uncategorized"],"maturity":"beta","audience":["developers"]} |
| allowed-tools | ["bash","git","grep","find"] |
Professional Electron application patterns for building secure, scalable desktop software.
Electron runs two processes:
// main.js — Main Process
const { app, BrowserWindow } = require('electron');
app.on('ready', () => {
const win = new BrowserWindow({
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
sandbox: true,
nodeIntegration: false,
enableRemoteModule: false,
},
});
win.loadFile('index.html');
});
Use preload scripts and ipcMain/ipcRenderer for secure communication.
// preload.js — Runs in renderer context with main process access
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('api', {
getData: () => ipcRenderer.invoke('get-data'),
onUpdate: (callback) => ipcRenderer.on('update', (_event, data) => callback(data)),
});
// main.js — Handle IPC calls
ipcMain.handle('get-data', async () => {
return { /* data */ };
});
ipcMain.on('set-data', (event, data) => {
event.reply('ack', { ok: true });
});
Enforce strict CSP headers to prevent XSS and injection attacks.
<!-- index.html -->
<meta http-equiv="Content-Security-Policy" content="
default-src 'none';
script-src 'self';
style-src 'self' 'unsafe-inline';
img-src 'self' data:;
font-src 'self';
connect-src 'self';
object-src 'none';
frame-ancestors 'none';
base-uri 'self';
form-action 'self';
">
Use React, Vue, or Svelte with local state.
// React + React Query example
import { useQuery, useMutation } from '@tanstack/react-query';
export const useAppData = () => {
return useQuery({
queryKey: ['app-data'],
queryFn: async () => window.api.getData(),
});
};
export const useUpdateData = () => {
return useMutation({
mutationFn: (data) => window.api.updateData(data),
});
};
Use Electron's ipcMain broadcast or external state service.
// main.js — Shared state via event emission
const { ipcMain } = require('electron');
let appState = {};
ipcMain.handle('state:get', () => appState);
ipcMain.handle('state:set', (event, newState) => {
appState = { ...appState, ...newState };
// Broadcast to all windows
mainWindow?.webContents?.send('state:changed', appState);
return appState;
});
// src/utils/__tests__/math.test.js
import { add, multiply } from '../math';
describe('Math utils', () => {
it('adds numbers correctly', () => {
expect(add(2, 3)).toBe(5);
});
});
Spectron is deprecated; use WebdriverIO with Electron driver.
// test/integration.js
import { remote } from 'webdriverio';
describe('Electron App', () => {
it('launches and shows window', async () => {
const app = await remote({
capabilities: {
browserName: 'chrome',
'wdio:electronService': {},
},
});
const title = await app.getTitle();
expect(title).toBe('My App');
await app.deleteSession();
});
});
Standard tool for packaging Electron apps.
// forge.config.js
module.exports = {
packagerConfig: {
asar: true,
icon: './assets/icon',
osxSign: {
identity: 'Developer ID Application: Company (ID)',
},
},
makers: [
{
name: '@electron-forge/maker-squirrel',
config: {
certificateFile: './cert.pfx',
certificatePassword: process.env.CERT_PASSWORD,
},
},
{
name: '@electron-forge/maker-dmg',
},
{
name: '@electron-forge/maker-zip',
},
],
};
# Build and sign for macOS
npm run make -- --platform darwin
# Notarize (Apple notarization)
xcrun altool --notarize-app --file MyApp.dmg --primary-bundle-id com.example.app \
-u developer@apple.com -p @keychain:Developer-ID
Use electron-updater for staged, delta-compressed updates.
// main.js
import { autoUpdater } from 'electron-updater';
autoUpdater.checkForUpdatesAndNotify();
autoUpdater.on('update-downloaded', () => {
autoUpdater.quitAndInstall();
});
Update server config:
autoUpdater.setFeedURL({
provider: 'github',
owner: 'myorg',
repo: 'myapp',
token: process.env.GH_TOKEN,
});
native-addon-build to match Electron's Node.js versionnodeIntegration: false)enableRemoteModule: false)sandbox: true)npm auditStay always-on-top: win.setAlwaysOnTop(true)
Tray menu: Menu.setApplicationMenu(createMenu())
Deep linking: Use deep-linking protocol + app.on('open-url')
Crash reporting: Integrate Sentry or similar