@@ -5,15 +5,29 @@ import { getManifest } from './manifest'
55import config from '../config'
66import { createSteps , withProgress } from './progress'
77
8+ // Fast mode for development - skips flashing system partition (the slowest)
9+ // Enable with ?fast=1 in URL
10+ const FAST_MODE = new URLSearchParams ( window . location . search ) . has ( 'fast' )
11+ if ( FAST_MODE ) {
12+ console . warn ( '[Flash] FAST MODE ENABLED - skipping system partition' )
13+ }
14+
815export const StepCode = {
916 INITIALIZING : 0 ,
1017 READY : 1 ,
11- CONNECTING : 2 ,
12- REPAIR_PARTITION_TABLES : 3 ,
13- ERASE_DEVICE : 4 ,
14- FLASH_SYSTEM : 5 ,
15- FINALIZING : 6 ,
16- DONE : 7 ,
18+ DEVICE_PICKER : 2 ,
19+ CONNECTING : 3 ,
20+ REPAIR_PARTITION_TABLES : 4 ,
21+ ERASE_DEVICE : 5 ,
22+ FLASH_SYSTEM : 6 ,
23+ FINALIZING : 7 ,
24+ DONE : 8 ,
25+ }
26+
27+ // Device types for the picker
28+ export const DeviceType = {
29+ COMMA_3 : 'comma3' , // comma 3 or 3X
30+ COMMA_4 : 'comma4' , // comma four
1731}
1832
1933export const ErrorCode = {
@@ -181,9 +195,10 @@ export class FlashManager {
181195 } catch ( err ) {
182196 console . error ( '[Flash] Failed to initialize image worker' )
183197 console . error ( err )
184- if ( err instanceof String && err . startsWith ( 'Not enough storage' ) ) {
198+ const message = err ?. message || String ( err )
199+ if ( message . startsWith ( 'Not enough storage' ) ) {
185200 this . #setError( ErrorCode . STORAGE_SPACE )
186- this . #setMessage( err )
201+ this . #setMessage( message )
187202 } else {
188203 this . #setError( ErrorCode . UNKNOWN )
189204 }
@@ -210,6 +225,12 @@ export class FlashManager {
210225 try {
211226 await this . device . connect ( usb )
212227 } catch ( err ) {
228+ // User cancelled the WebUSB dialog or no device was selected - not an error
229+ if ( err . name === 'NotFoundError' ) {
230+ console . info ( '[Flash] No device selected' )
231+ this . #setStep( StepCode . READY )
232+ return
233+ }
213234 console . error ( '[Flash] Connection error' , err )
214235 this . #setError( ErrorCode . LOST_CONNECTION )
215236 this . #setConnected( false )
@@ -353,10 +374,16 @@ export class FlashManager {
353374 this . #setProgress( 0 )
354375
355376 // Exclude GPT images and persist image, and pick correct userdata image to flash
356- const systemImages = this . manifest
377+ let systemImages = this . manifest
357378 . filter ( ( image ) => ! image . gpt && image . name !== 'persist' )
358379 . filter ( ( image ) => ! image . name . startsWith ( 'userdata_' ) || image . name === this . #userdataImage)
359380
381+ // In fast mode, skip the system partition (slowest to flash)
382+ if ( FAST_MODE ) {
383+ systemImages = systemImages . filter ( ( image ) => image . name !== 'system' )
384+ console . info ( '[Flash] Fast mode: skipping system partition' )
385+ }
386+
360387 if ( ! systemImages . find ( ( image ) => image . name === this . #userdataImage) ) {
361388 console . error ( `[Flash] Did not find userdata image "${ this . #userdataImage} "` )
362389 this . #setError( ErrorCode . UNKNOWN )
@@ -414,7 +441,8 @@ export class FlashManager {
414441 async start ( ) {
415442 if ( this . step !== StepCode . READY ) return
416443 await this . #connect( )
417- if ( this . error !== ErrorCode . NONE ) return
444+ // Check if connection was cancelled (step went back to READY) or failed
445+ if ( this . step === StepCode . READY || this . error !== ErrorCode . NONE ) return
418446 let start = performance . now ( )
419447 await this . #repairPartitionTables( )
420448 console . info ( `Repaired partition tables in ${ ( ( performance . now ( ) - start ) / 1000 ) . toFixed ( 2 ) } s` )
0 commit comments