Add Electron quickstart app#280
Add Electron quickstart app#280Brian Plattenburg (bplattenburg) wants to merge 2 commits intomainfrom
Conversation
New /electron/ quickstart implementing the Tasks demo on Electron with the Ditto JS SDK 5.0.0. The Ditto Node SDK runs in Electron's main process (full peer-to-peer sync over LAN + websocket), and a React + TypeScript renderer mirrors the javascript-web app, communicating with Ditto entirely via a contextBridge IPC API. The main-process observer fans task list updates out to all renderer windows. Why: customer ask for an Electron reference app. This is the first quickstart that runs the Ditto Node SDK inside Electron's main process, so it documents the BLE/AWDL transport caveats for unsigned dev builds and uses N-API prebuilds (verified to load in Electron without @electron/rebuild). Dev-only scope: no CI, no installers.
There was a problem hiding this comment.
Pull request overview
Adds a new Electron-based “Tasks” quickstart that runs the Ditto Node SDK in Electron’s main process and exposes a typed IPC API to a React/TypeScript renderer.
Changes:
- Introduces a new
/electron/app scaffolded with electron-vite + React + Tailwind, including main/preload/renderer separation. - Implements a Ditto-backed tasks CRUD flow in the main process with IPC fan-out of task updates to renderer windows.
- Updates the repo root README to link to the new Electron quickstart.
Reviewed changes
Copilot reviewed 24 out of 27 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Adds Electron quickstart link to the repo index. |
| electron/.gitignore | Ignores Electron build outputs and local deps. |
| electron/electron.vite.config.ts | electron-vite build config for main/preload/renderer. |
| electron/eslint.config.js | ESLint flat config for TS + React + Prettier. |
| electron/package.json | Declares Electron quickstart dependencies and scripts. |
| electron/package-lock.json | Locks dependency graph for the Electron app. |
| electron/postcss.config.js | PostCSS config for Tailwind + autoprefixer. |
| electron/prettier.config.js | Prettier formatting settings for the Electron app. |
| electron/README.md | Electron quickstart documentation and architecture overview. |
| electron/tailwind.config.js | Tailwind content scanning configuration. |
| electron/tsconfig.json | TS project references setup. |
| electron/tsconfig.node.json | TS config for main/preload TypeScript. |
| electron/tsconfig.web.json | TS config for renderer TypeScript. |
| electron/src/types.ts | Shared task + IPC channel/type definitions. |
| electron/src/main/index.ts | Electron main process entry + IPC handlers + window creation. |
| electron/src/main/env.ts | Loads required Ditto env vars from repo root .env. |
| electron/src/main/ditto.ts | Ditto initialization, sync config, observer, and CRUD helpers. |
| electron/src/preload/index.ts | Exposes typed IPC-backed window.ditto API via contextBridge. |
| electron/src/preload/api.d.ts | Global window.ditto TypeScript declaration. |
| electron/src/renderer/vite-env.d.ts | Vite client typings for the renderer. |
| electron/src/renderer/index.html | Renderer HTML shell and CSP meta. |
| electron/src/renderer/index.css | Tailwind directives and full-height layout. |
| electron/src/renderer/main.tsx | React root bootstrap. |
| electron/src/renderer/App.tsx | App wiring for Ditto info, sync toggle, and task list callbacks. |
| electron/src/renderer/components/DittoInfo.tsx | Displays app identity + sync toggle UI. |
| electron/src/renderer/components/ErrorMessage.tsx | Dismissible error overlay component. |
| electron/src/renderer/components/TaskList.tsx | Task list UI with edit/toggle/delete/create actions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Bump Node engine and README to >=22.12 to match Electron 42's bundled runtime (avoids strict-engines install failures). - Add connect-src to the renderer CSP so Vite HMR's WebSocket can connect during dev. - Drop sandbox: false from BrowserWindow webPreferences and ship the preload as CommonJS (.cjs). contextBridge + ipcRenderer work cleanly under the default sandbox, and ESM preloads silently fail to load when sandboxed. - Hydrate initial renderer state via a new tasks:get IPC method to close a race: the main-process observer fires when cloud sync delivers tasks, often before the BrowserWindow has registered its IPC listener. Renderer now subscribes first, then fetches initial state.
|
Thanks @copilot — addressed three, dismissing one, deferring two. Details: Addressed in b0f9278:
Dismissed:
Deferred (matches
Bonus (caught while validating the sandbox+CJS preload change): the main-process observer fires when cloud sync delivers tasks, often before the BrowserWindow has registered its IPC listener — leaving the renderer with an empty list. b0f9278 adds a |
Summary
/electron/quickstart implementing the Tasks demo on Electron with Ditto JS SDK 5.0.0.javascript-weband communicates with Ditto via acontextBridgeIPC API. The main-process observer fans task updates out to all renderer windows.Why
Customer ask for an Electron reference app. First quickstart running Ditto's Node SDK inside Electron — documents the BLE/AWDL transport caveats for unsigned dev builds and uses N-API prebuilds (verified to load in Electron without
@electron/rebuild).Validation
Validated locally on macOS (Apple Silicon). Requesting Aaron LaBeau (@biozal) to validate on Windows (x64) before merge.