Electron main process and IPC development guidelines for Gemini-Subtitle-Pro. Use when working with IPC handlers, preload scripts, native integrations (ffmpeg, whisper, yt-dlp), file system operations, and desktop-specific features. Covers security requirements, IPC patterns, and cross-process communication.
Establish secure and consistent patterns for Electron main process development in Gemini-Subtitle-Pro.
Automatically activates when working on:
electron/main.ts using ipcMain.handle()electron/preload.tscontextBridgesrc/types/electron.d.tsfeature:action conventionThese settings MUST be maintained in electron/main.ts:
const mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: false, // NEVER change to true
contextIsolation: true, // NEVER change to false
sandbox: true, // NEVER change to false
preload: path.join(__dirname, 'preload.js'),
},
});
Why?
nodeIntegration: false - Prevents renderer from accessing Node.js APIs directlycontextIsolation: true - Separates preload from renderer contextsandbox: true - Limits preload script capabilities// electron/main.ts
ipcMain.handle('video:compress', async (event, options: CompressOptions) => {
try {
const result = await compressVideo(options);
return { success: true, data: result };
} catch (error) {
return { success: false, error: error.message };
}
});
// electron/preload.ts
contextBridge.exposeInMainWorld('electronAPI', {
compressVideo: (options: CompressOptions) => ipcRenderer.invoke('video:compress', options),
});
// src/types/electron.d.ts
interface ElectronAPI {
compressVideo: (options: CompressOptions) => Promise<CompressResult>;
}
declare global {
interface Window {
electronAPI: ElectronAPI;
}
}
// src/services/video/compressor.ts
const result = await window.electronAPI.compressVideo(options);
electron/
├── main.ts # Main process entry, IPC handlers
├── preload.ts # Context bridge
├── logger.ts # Logging utilities
├── i18n.ts # i18n for main process
├── locales/ # Main process locales
└── services/ # Native service integrations
├── ffmpegService.ts
├── localWhisper.ts
└── videoPreviewTranscoder.ts
Use feature:action format:
// ✅ Good
'video:compress';
'audio:extract';
'subtitle:export';
'file:select';
'app:getVersion';
// ❌ Bad
'compressVideo';
'COMPRESS_VIDEO';
'video_compress';
For detailed guidelines, see the resources directory: