--- tags: [electron, setup, architecture] session: 1 duration: 2 hours status: ready --- # Session 1 — The Desktop Web: How Electron Works ## 🎯 Objectives - Understand what Electron is and why it exists - Set up the development environment - Run a working Electron app - Understand the Main vs Renderer process model --- ## 🧠 Concepts Covered ### What is Electron? Electron lets you build desktop apps using HTML, CSS, and JavaScript. It bundles two things together: - **Chromium** → renders your UI (like a built-in browser) - **Node.js** → gives you access to the filesystem, OS, and more > Real apps built with Electron: VS Code, Slack, Discord, Figma, Notion ### Desktop vs Web Apps | Web App | Desktop App | |---------|-------------| | Runs in browser | Runs natively on OS | | No file system access | Full file system access | | URL-based | Has its own window/icon | | Auto-updated | Needs packaging/installer | ### The Two-Process Model ⚠️ (Most Important Concept) ``` ┌─────────────────────────────┐ │ MAIN PROCESS │ ← Node.js world │ - Creates windows │ File system, OS APIs │ - App lifecycle │ │ - Background logic │ └────────────┬────────────────┘ │ IPC (messages) ┌────────────▼────────────────┐ │ RENDERER PROCESS │ ← Browser world │ - Displays your HTML/CSS │ DOM, UI events │ - One per window │ └─────────────────────────────┘ ``` **Key rule:** Renderer cannot directly access Node.js. They communicate via IPC (covered in Session 4). --- ## 🖥 Talking Points 1. Open VS Code and show the folder structure of a blank Electron app 2. Walk through `package.json` — point out `"main": "main.js"` 3. Open `main.js` — explain `app.whenReady()` and `BrowserWindow` 4. Open `index.html` — show it's just normal HTML 5. Run `npm start` — a window appears! --- ## 💻 Live Demo ```js // main.js — bare minimum Electron app const { app, BrowserWindow } = require('electron') function createWindow() { const win = new BrowserWindow({ width: 800, height: 600 }) win.loadFile('index.html') } app.whenReady().then(createWindow) ``` ```html