|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Browser-based tool for flashing Magisk-patched `init_boot.img` to OnePlus Open (CPH2551) via WebUSB. Requires Chromium-based browsers (Chrome, Edge) — no Firefox/Safari support. Fetches patched images from the CruelKernel/oneplus_kernel_patcher GitHub repository and matches them to the device's firmware version. |
| 8 | + |
| 9 | +## Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +npm install # Install dependencies |
| 13 | +npm run dev # Dev server at http://localhost:5173 |
| 14 | +npm run build # TypeScript check + Vite production build |
| 15 | +npm run lint # ESLint |
| 16 | +npm run preview # Preview production build |
| 17 | +docker compose up # Docker dev at http://localhost:8080 |
| 18 | +``` |
| 19 | + |
| 20 | +## Architecture |
| 21 | + |
| 22 | +**Single-page React app** built with Vite + TypeScript + Tailwind CSS. |
| 23 | + |
| 24 | +### State Machine (`src/App.tsx`) |
| 25 | + |
| 26 | +The app is driven by a `FlashState` union type (23 states) that controls the entire UI and workflow: |
| 27 | + |
| 28 | +`IDLE → ADB_CONNECTING → ADB_CONNECTED → DETECTING_FIRMWARE → FIRMWARE_DETECTED → FETCHING_RELEASES → RELEASE_MATCHED → DOWNLOADING_IMAGE → DOWNLOAD_COMPLETE → CONFIRMING_FLASH → REBOOTING_BOOTLOADER → WAITING_FASTBOOT → FASTBOOT_CONNECTING → FASTBOOT_CONNECTED → FLASHING → FLASH_COMPLETE → REBOOTING_SYSTEM → SUCCESS` |
| 29 | + |
| 30 | +State transitions happen in `App.tsx` which is the main (~600 line) component containing all UI rendering and orchestration logic. |
| 31 | + |
| 32 | +### Services (`src/services/`) |
| 33 | + |
| 34 | +- **adb.ts** — WebUSB ADB connection via `@yume-chan/adb`. Reads device model, firmware version, serial number. Reboots to bootloader. |
| 35 | +- **fastboot.ts** — Fastboot protocol via `android-fastboot`. Validates unlocked bootloader, flashes `init_boot` partition with progress callbacks. |
| 36 | +- **github.ts** — Fetches releases from CruelKernel/oneplus_kernel_patcher. Caches in memory. Matches device firmware version to release tags (exact match on format `CPH2551_15.0.0.822(EX01)`). |
| 37 | +- **download.ts** — Downloads GitHub release assets through a CORS proxy (`api.codetabs.com`). Streams with progress tracking. |
| 38 | + |
| 39 | +### Types (`src/types/`) |
| 40 | + |
| 41 | +- **index.ts** — Core types: `FlashState`, `DeviceInfo`, `AppState`, progress types, GitHub API types. |
| 42 | +- **android-fastboot.d.ts** — Type declarations for the untyped `android-fastboot` library. |
| 43 | + |
| 44 | +### Utils (`src/utils/version.ts`) |
| 45 | + |
| 46 | +Parses firmware version strings (regex: `CPH\d+_\d+\.\d+\.\d+\.\d+\([A-Z0-9]+\)`), validates device is CPH2551, formats file sizes. |
| 47 | + |
| 48 | +## Key Patterns |
| 49 | + |
| 50 | +- Services are held as refs (`useRef`) in App.tsx — singleton instances persisted across renders. |
| 51 | +- ADB credentials stored in browser localStorage under key `'oneplus-flasher'`. |
| 52 | +- GitHub Pages deployment via `.github/workflows/deploy.yml` uses `VITE_BASE_PATH` env var for subdirectory routing. |
| 53 | +- No test framework is configured. |
0 commit comments