@@ -19,9 +19,13 @@ export class AndroidProject extends Project {
1919 }
2020
2121 public attach ( tnsArgs ?: string [ ] ) : DebugResult {
22+ let args : string [ ] = [ "--start" ] ;
23+ args = args . concat ( tnsArgs ) ;
24+
25+ let debugProcess : ChildProcess = super . executeDebugCommand ( args ) ;
2226 let tnsOutputEventEmitter = new EventEmitter ( ) ;
23- setTimeout ( ( ) => tnsOutputEventEmitter . emit ( 'readyForConnection' ) ) ; // emit readyForConnection on the next tick
24- return { tnsProcess : null , tnsOutputEventEmitter : tnsOutputEventEmitter } ;
27+ this . configureReadyEvent ( debugProcess . stdout , tnsOutputEventEmitter , true ) ;
28+ return { tnsProcess : debugProcess , tnsOutputEventEmitter : tnsOutputEventEmitter } ;
2529 }
2630
2731 public debug ( options : { stopOnEntry : boolean , watch : boolean } , tnsArgs ?: string [ ] ) : DebugResult {
@@ -32,19 +36,25 @@ export class AndroidProject extends Project {
3236
3337 let debugProcess : ChildProcess = super . executeDebugCommand ( args ) ;
3438 let tnsOutputEventEmitter : EventEmitter = new EventEmitter ( ) ;
35- this . configureReadyEvent ( debugProcess . stdout , tnsOutputEventEmitter ) ;
39+ this . configureReadyEvent ( debugProcess . stdout , tnsOutputEventEmitter , false ) ;
3640 return { tnsProcess : debugProcess , tnsOutputEventEmitter : tnsOutputEventEmitter } ;
3741 }
3842
39- private configureReadyEvent ( readableStream : stream . Readable , eventEmitter : EventEmitter ) : void {
43+ private configureReadyEvent ( readableStream : stream . Readable , eventEmitter : EventEmitter , attach : boolean ) : void {
4044 let debugPort = null ;
4145 new scanner . StringMatchingScanner ( readableStream ) . onEveryMatch ( new RegExp ( "device: .* debug port: [0-9]+" ) , ( match : scanner . MatchFound ) => {
4246 //device: {device-name} debug port: {debug-port}
4347 debugPort = parseInt ( ( < string > match . matches [ 0 ] ) . match ( "(?:debug port: )([\\d]{5})" ) [ 1 ] ) ;
48+ if ( attach ) {
49+ // wait a little before trying to connect, this gives a chance for adb to be able to connect to the debug socket
50+ setTimeout ( ( ) => { eventEmitter . emit ( 'readyForConnection' , debugPort ) ; } , 500 ) ;
51+ }
4452 } ) ;
45- new scanner . StringMatchingScanner ( readableStream ) . onEveryMatch ( '# NativeScript Debugger started #' , ( match : scanner . MatchFound ) => {
46- // wait a little before trying to connect, this gives a chance for adb to be able to connect to the debug socket
47- setTimeout ( ( ) => { eventEmitter . emit ( 'readyForConnection' , debugPort ) ; } , 500 ) ;
48- } ) ;
53+ if ( ! attach ) {
54+ new scanner . StringMatchingScanner ( readableStream ) . onEveryMatch ( '# NativeScript Debugger started #' , ( match : scanner . MatchFound ) => {
55+ // wait a little before trying to connect, this gives a chance for adb to be able to connect to the debug socket
56+ setTimeout ( ( ) => { eventEmitter . emit ( 'readyForConnection' , debugPort ) ; } , 500 ) ;
57+ } ) ;
58+ }
4959 }
5060}
0 commit comments