11"use strict" ;
2- var __createBinding = ( this && this . __createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
2+ var __createBinding = ( this && this . __createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
33 if ( k2 === undefined ) k2 = k ;
44 var desc = Object . getOwnPropertyDescriptor ( m , k ) ;
55 if ( ! desc || ( "get" in desc ? ! m . __esModule : desc . writable || desc . configurable ) ) {
6- desc = { enumerable : true , get : function ( ) { return m [ k ] ; } } ;
6+ desc = { enumerable : true , get : function ( ) { return m [ k ] ; } } ;
77 }
88 Object . defineProperty ( o , k2 , desc ) ;
9- } ) : ( function ( o , m , k , k2 ) {
9+ } ) : ( function ( o , m , k , k2 ) {
1010 if ( k2 === undefined ) k2 = k ;
1111 o [ k2 ] = m [ k ] ;
1212} ) ) ;
13- var __setModuleDefault = ( this && this . __setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
13+ var __setModuleDefault = ( this && this . __setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
1414 Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
15- } ) : function ( o , v ) {
15+ } ) : function ( o , v ) {
1616 o [ "default" ] = v ;
1717} ) ;
1818var __importStar = ( this && this . __importStar ) || function ( mod ) {
@@ -72,6 +72,8 @@ function launchEmulator(systemImageApiLevel, target, arch, profile, cores, ramSi
7272 }
7373 // start emulator
7474 console . log ( 'Starting emulator.' ) ;
75+ console . log ( 'Starting tristans emulator.' ) ;
76+
7577 // Add a small delay to ensure emulator process starts properly
7678 yield exec . exec ( `sh -c \\"${ process . env . ANDROID_HOME } /emulator/emulator -port ${ port } -avd "${ avdName } " ${ emulatorOptions } &"` , [ ] , {
7779 listeners : {
@@ -82,8 +84,6 @@ function launchEmulator(systemImageApiLevel, target, arch, profile, cores, ramSi
8284 } ,
8385 } ,
8486 } ) ;
85- // Wait a few seconds for emulator process to initialize before polling
86- yield delay ( 5000 ) ;
8787 // wait for emulator to complete booting
8888 yield waitForDevice ( port , emulatorBootTimeout ) ;
8989 yield adb ( port , `shell input keyevent 82` ) ;
@@ -134,11 +134,46 @@ function adb(port, command) {
134134 */
135135function waitForDevice ( port , emulatorBootTimeout ) {
136136 return __awaiter ( this , void 0 , void 0 , function * ( ) {
137- let booted = false ;
138- let attempts = 0 ;
137+ const startTime = Date . now ( ) ;
139138 const retryInterval = 2 ; // retry every 2 seconds
140- const maxAttempts = emulatorBootTimeout / 2 ;
139+ // Step 1: Poll until device appears in ADB
140+ console . log ( 'Waiting for emulator device to connect...' ) ;
141+ let deviceConnected = false ;
142+ while ( ! deviceConnected ) {
143+ const elapsedSeconds = ( Date . now ( ) - startTime ) / 1000 ;
144+ if ( elapsedSeconds > emulatorBootTimeout ) {
145+ throw new Error ( 'Timeout waiting for emulator device to connect.' ) ;
146+ }
147+ try {
148+ // Try to get device state - will fail if device doesn't exist
149+ let state = '' ;
150+ yield exec . exec ( `adb -s emulator-${ port } get-state` , [ ] , {
151+ listeners : {
152+ stdout : ( data ) => {
153+ state += data . toString ( ) ;
154+ } ,
155+ } ,
156+ } ) ;
157+ if ( state . trim ( ) === 'device' ) {
158+ deviceConnected = true ;
159+ }
160+ }
161+ catch ( error ) {
162+ // Device not found yet, keep waiting
163+ console . warn ( error instanceof Error ? error . message : error ) ;
164+ }
165+ if ( ! deviceConnected ) {
166+ yield delay ( retryInterval * 1000 ) ;
167+ }
168+ }
169+ console . log ( 'Device connected. Waiting for boot to complete...' ) ;
170+ // Step 2: Poll for boot completion
171+ let booted = false ;
141172 while ( ! booted ) {
173+ const elapsedSeconds = ( Date . now ( ) - startTime ) / 1000 ;
174+ if ( elapsedSeconds > emulatorBootTimeout ) {
175+ throw new Error ( 'Timeout waiting for emulator to boot.' ) ;
176+ }
142177 try {
143178 let result = '' ;
144179 yield exec . exec ( `adb -s emulator-${ port } shell getprop sys.boot_completed` , [ ] , {
@@ -151,19 +186,14 @@ function waitForDevice(port, emulatorBootTimeout) {
151186 if ( result . trim ( ) === '1' ) {
152187 console . log ( 'Emulator booted.' ) ;
153188 booted = true ;
154- break ;
155189 }
156190 }
157191 catch ( error ) {
158192 console . warn ( error instanceof Error ? error . message : error ) ;
159193 }
160- if ( attempts < maxAttempts ) {
194+ if ( ! booted ) {
161195 yield delay ( retryInterval * 1000 ) ;
162196 }
163- else {
164- throw new Error ( `Timeout waiting for emulator to boot.` ) ;
165- }
166- attempts ++ ;
167197 }
168198 } ) ;
169199}
0 commit comments