How 2045matrix/etcher works
Project type and purpose
• This is Etcher, a cross-platform desktop application (built on Electron) for flashing OS images to SD cards and USB drives. It comprises a GUI (renderer process), a main process, and a privileged “sidecar” or child-process for low-level tasks (drive scanning, image writing, elevation).
File structure
• Top-level:
• lib/gui/app – The renderer code (React/TypeScript) for the UI.
• lib/gui/index.html, preload.ts, renderer.ts – Electron entry points for the renderer process.
• lib/gui/etcher.ts, lib/gui/menu.ts, lib/gui/webapi.ts – The main process’s bootstrap and menu/web-API glue.
• lib/util & lib/shared – Shared business logic (drive scanning, image-writer, permissions, utils, constants).
• Sidecar: package.json’s “pkg-sidecar.json” and tsconfig.sidecar.json configure a separate node process that runs the low-level image-writing code under elevated privileges.
• Configuration: forge.config.ts, webpack.config.ts for Electron Forge/Webpack.
• Tests under tests/gui, tests/shared, tests/util – Unit and E2E specs.
• assets, docs, CI/CD workflows, signing secrets – Packaging and release infrastructure.
README for additional insights
• Confirms it is an Electron app, supports Linux, Windows, macOS.
• Mentions safety checks, complete‐write verification, and USB-boot flashing.
a. Main components:
1. Renderer Process (UI):
• React components (drive-selector, flash-results, progress-button, settings, etc.)
• i18n, CSS, models (selection-state, flash-state).
2. Main Process:
• BrowserWindow creation, menu, IPC bridges, window progress APIs, exception reporting, analytics.
3. Preload Script:
• Exposes safe, limited APIs to the renderer (via contextBridge).
4. Sidecar / Child Process:
• Elevated-privilege subprocess for drive scanning and image writing (through lib/util and lib/shared/sudo).
5. Shared Libraries:
• Cross-process modules: drive constraints, permissions, exit codes, messaging.
6. External Services:
• OS APIs: dialog, notifications, network-drive enumeration.
• Analytics endpoint.
• Exception reporter (Sentry or similar).
b. Relationships & interactions:
• Renderer ←→ Preload: UI calls fetchDrives(), flashImage() via exposed API.
• Preload → Main Process (IPC): Sanitized requests forwarded to main.
• Main Process ↔ Sidecar: Spawns the sidecar for privileged operations; communicates over stdio or IPC.
• Sidecar → Shared Modules: Uses util.drive-scanner, util.child-writer, shared/sudo to perform tasks.
• Failures & progress emissions bubble back: Sidecar → Main → Renderer for UI updates.
• External OS API calls from both main and renderer (notifications, dialogs).
• Analytics & exception reporter modules invoked in main or renderer.
c. Architectural patterns / design principles:
• Process separation: Renderer for UI, Main for orchestration, Sidecar for elevation.
• Preload sandbox: Minimizes renderer privileges via contextBridge.
• Shared code: Avoid duplication by centralizing logic in lib/shared and lib/util.
• Event-driven IPC: Asynchronous messages for progress, errors.
• Modular React components: Single Responsibility, composability.
d. Key technologies / frameworks:
• Electron (main, renderer, preload).
• React + TypeScript for UI.
• Electron Forge + Webpack for bundling.
• Node.js child_process / execa for sidecar operations.
• Sudo-prompt or platform-specific elevation modules.
• i18next (or custom i18n) for localization.
• Jest/WebdriverIO for tests.