You are an expert in Electron development for building cross-platform desktop applications.
src/
├── main/ # Main process code
│ ├── index.ts # Entry point
│ ├── ipc/ # IPC handlers
│ └── utils/ # Utilities
├── renderer/ # Renderer process code
│ ├── components/ # UI components
│ ├── pages/ # Application pages
│ └── styles/ # Stylesheets
├── preload/ # Preload scripts
│ └── index.ts # Expose APIs to renderer
└── shared/ # Shared types and utilities
// main.js
const win = new BrowserWindow({
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
preload: path.join(__dirname, 'preload.js')
}
});
// preload.js
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
sendMessage: (channel, data) => {
const validChannels = ['toMain'];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
onMessage: (channel, callback) => {
const validChannels = ['fromMain'];
if (validChannels.includes(channel)) {
ipcRenderer.on(channel, (event, ...args) => callback(...args));
}
}
});
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
const { ipcMain } = require('electron');
ipcMain.handle('read-file', async (event, filePath) => {
const content = await fs.promises.readFile(filePath, 'utf-8');
return content;
});
ipcMain.on('save-file', (event, { path, content }) => {
fs.writeFileSync(path, content);
event.reply('file-saved', { success: true });
});
// Using exposed API from preload
const content = await window.electronAPI.readFile('/path/to/file');
const { BrowserWindow } = require('electron');
function createWindow() {
const win = new BrowserWindow({
width: 1200,
height: 800,
minWidth: 800,
minHeight: 600,
webPreferences: {
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
}
});
// Handle window events
win.on('closed', () => {
// Cleanup
});
// Load content
if (process.env.NODE_ENV === 'development') {
win.loadURL('http://localhost:3000');
win.webContents.openDevTools();
} else {
win.loadFile('dist/index.html');
}
}
const { autoUpdater } = require('electron-updater');
autoUpdater.on('update-available', () => {
// Notify user
});
autoUpdater.on('update-downloaded', () => {
autoUpdater.quitAndInstall();
});
app.whenReady().then(() => {
autoUpdater.checkForUpdatesAndNotify();
});
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Set up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.
CLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Set up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.
CLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).