Electron Development Guidelines
Project Structure
- •Main Process:
electron/main.ts - •Preload Script:
electron/preload.ts - •IPC Handlers:
electron/mod-manager.ts(and other managers) - •Renderer:
src/(React)
IPC Communication
- •Pattern: Use
ipcRenderer.invoke(renderer) <->ipcMain.handle(main) for all async operations. - •Safety: NEVER expose entire Node.js modules to the renderer. Use
contextBridgeinpreload.tsto expose specific API methods. - •Typing: Ensure input arguments and return types are strictly typed.
Code Style
- •Use
async/awaitfor asynchronous operations. - •Handle errors gracefully in
ipcMainhandlers and return meaningful error messages to the renderer. - •Use
path.joinfor file paths to ensure cross-platform compatibility.
File System Operations
- •Use
fs/promisesfor file I/O where possible. - •Validate paths received from the renderer to prevent directory traversal attacks (though low risk in local app, good practice).
Window Management
- •Use
BrowserWindowfor creating windows. - •Manage window state (maximize, minimize, close) via IPC events.