How electron/fiddle works
Project Type and Purpose
• This is an Electron desktop application ("Electron Fiddle") that lets users write, run, save, and package small Electron experiments.
• It combines a “backend” (the Electron Main process), a “frontend” (the Electron Renderer process built with React/Monaco), a secure Preload bridge, external runner processes, and integrations with NPM & GitHub.
Out Top-Level Components
A. Main Process (src/main)
– Manages application lifecycle, menus, dialogs (about-panel.ts, menu.ts, dialogs.ts).
– Handles file I/O, templates (templates.ts), first-run checks, version management (versions.ts), update logic (squirrel.ts, update.ts), Sentry error reporting (sentry.ts), and command-line flags.
– Talks to external services: NPM registry (npm.ts), GitHub Gist via Octokit, Electron releases (fetch-releases tool).
B. Preload Bridge (src/preload/preload.ts)
– Exposes a secure, limited API surface to the Renderer over IPC channels defined in ipc-events.ts.
– Functions include read/write fiddle, fetch versions, run code, open external links.
C. Renderer Process (src/renderer + src/less)
– React + TypeScript UI using Monaco Editor.
– Components for file tree, package manager, version selector, editors, outputs, settings, tours, etc.
– State management (state.ts), task runner (task-runner.ts), runner control (runner.ts), remote loader for user code.
– Communicates with Main via IPC.
“External Runner” Process
– When the user clicks “Run,” Main/Renderer spawn a separate Electron child‐process to execute the user’s fiddle.
External Services
• NPM Registry
• GitHub Gist / API (via Octokit)
• Electron Releases (GitHub)
• Sentry (error reporting)
Build/Tooling (outside “Electron App”)
• Webpack configs (tools/webpack/…), which bundle main, renderer, and preload.
• Forge config (forge.config.ts) for packaging.
• CI/CD flows (.circleci, GitHub workflows).
Architectural Patterns
• Multi-process separation (Main vs Renderer vs Runner).
• IPC-based communication, with a Preload context for secure channels.
• Modular code organization: src/main/utils, src/renderer/utils, src/less for theming.
• Packaging via electron-forge + Squirrel auto-updater.
Final Checklist
– Main process modules: lifecycle, menus, file I/O, updates, network.
– Preload: secure IPC API.
– Renderer: React UI, state, task runner, Monaco editor.
– Electron Runner: user-code execution sandbox.
– External services: NPM, GitHub, Sentry, update server.
– Build/tooling: Webpack, Forge, CI pipeline.