How jfo8000/scratchjr-desktop works
Project type and purpose
• This is a full-stack desktop application: an Electron-based port of the ScratchJr HTML5 app.
• Purpose: Host the existing ScratchJr editor (originally for iPad/Android) inside a native desktop wrapper (Windows/Mac), providing filesystem access, packaging, and small persistent storage via SQL.js.
File structure
• Top‐level:
• src/main.js + src/electronClient.js → Electron “main” process entry points.
• src/app/… → The entire ScratchJr HTML5/JavaScript/CSS application (shared code with mobile).
• Patterns:
• Electron’s two‐process architecture (Main vs Renderer).
• “tabletInterface” abstraction (in mobile) is replaced by ElectronDesktopInterface in renderer.
• SQL.js embedded DB for project storage.
• Assets (images, audio, SVG) delivered by the web app.
• Config & build scripts:
• package.json (npm scripts, dependencies, lint).
• forge.config.js (packaging rules).
• .travis.yml & appveyor.yml (CI builds).
README for additional insights
• Confirms Electron + Electron Forge for packaging.
• Describes “ElectronDesktopInterface” layer bridging HTML5 code to OS services.
• Mentions SQL.js DB with a PROJECTFILES table for embedded assets.
Main components
a. Native Desktop Layer (Electron Main Process)
• Responsibilities: packaging, installers, launching renderer, handling filesystem I/O, database reads/writes.
• Modules: main.js, electronClient.js.
b. Renderer / Web Layer (Electron Renderer Process)
• Hosts the ScratchJr HTML5 app (src/app/) inside a Chromium webview.
• Components:
• AppEntry / index.html / editor.html UI pages.
• Editor engine (blocks, runtime, stage, sprite modules).
• UI modules (Palette, Library, Alerts, ScriptsPane).
• Paint editor module (SVGTools, Camera, Ghost layers).
• Lobby / sample loader.
• Localization & settings.
c. ElectronDesktopInterface
• Sits in the renderer as a “third tabletInterface” implementation.
• Routes calls for filesystem & recording: either WebRTC (audio/video) or IPC to main process.
d. Database Layer (SQL.js)
• Embedded SQLite compiled to JavaScript.
• Stores projects & assets in three tables: original tables + PROJECTFILES.
• Exposed via tabletInterface → main process or direct SQL.js calls.
e. Assets & Storage
• Project files stored in SQL.js; no external FS clutter.
f. Packaging & Deployment
• Electron Forge config → produces .dmg (Mac), .exe (Windows) installers.
• CI pipelines (Travis, AppVeyor).
Relationships & interactions
• User clicks UI in renderer → ScratchJr JS modules → if need OS service → ElectronDesktopInterface → either Web API (WebRTC) or IPC → main process → OS FS or native dialogs.
• Renderer loads/saves project data via SQL.js library embedded in app or via main process.
Architectural patterns & principles
• Two-tier Electron architecture: separation of concerns between native OS boundary (main) and UI logic (renderer).
• Modular web app: editor engine, UI, paint editor, lobby.
• Abstraction layer (tabletInterface) to keep codebase portable across mobile & desktop.
• Single-page application model within editor.html.