@@ -63,6 +63,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
6363 this . _scriptsById = new Map < WebKitProtocol . Debugger . ScriptId , WebKitProtocol . Debugger . Script > ( ) ;
6464 this . _committedBreakpointsByUrl = new Map < string , WebKitProtocol . Debugger . BreakpointId [ ] > ( ) ;
6565 this . _setBreakpointsRequestQ = Promise . resolve < void > ( ) ;
66+ this . _lastOutputEvent = null ;
6667 this . fireEvent ( { seq : 0 , type : 'event' , event : 'clearTargetContext' } ) ;
6768 }
6869
@@ -121,7 +122,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
121122 Services . logger . log ( `${ args . request } (${ JSON . stringify ( args ) } )` ) ;
122123 }
123124
124- private processRequest ( args : DebugProtocol . IRequestArgs ) {
125+ private processRequest ( args : DebugProtocol . IRequestArgs ) : Promise < void > {
125126 this . configureLoggingForRequest ( args ) ;
126127 // Initialize the request
127128 Services . appRoot = args . appRoot ;
@@ -147,30 +148,23 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
147148 cliCommand . tnsProcess . on ( 'close' , ( code , signal ) => { Services . logger . error ( `The tns command finished its execution with code ${ code } .` , Tags . FrontendMessage ) ; } ) ;
148149 }
149150
151+ let promiseResolve = null ;
152+ let promise : Promise < void > = new Promise < void > ( ( res , rej ) => { promiseResolve = res ; } ) ;
150153 // Attach to the running application
151- let connectionEstablished = cliCommand . backendIsReadyForConnection . then ( ( connectionToken : string | number ) => {
152- if ( this . _request . isAndroid ) {
153- Services . logger . log ( `Attaching to application on port ${ connectionToken } ` ) ;
154- let androidConnection = new AndroidConnection ( ) ;
155- this . setConnection ( androidConnection ) ;
156- let port : number = < number > connectionToken ;
157- return androidConnection . attach ( port , 'localhost' ) ;
158- }
159- if ( this . _request . isIos ) {
160- Services . logger . log ( `Attaching to application on socket path ${ connectionToken } ` ) ;
161- let iosConnection = new IosConnection ( ) ;
162- this . setConnection ( iosConnection ) ;
163- let socketFilePath : string = < string > connectionToken ;
164- return iosConnection . attach ( socketFilePath ) ;
165- }
154+ cliCommand . tnsOutputEventEmitter . on ( 'readyForConnection' , ( connectionToken : string | number ) => {
155+ connectionToken = this . _request . isAndroid ? this . _request . androidProject . getDebugPortSync ( ) : connectionToken ;
156+ Services . logger . log ( `Attaching to application on ${ connectionToken } ` ) ;
157+ let connection : INSDebugConnection = this . _request . isAndroid ? new AndroidConnection ( ) : new IosConnection ( ) ;
158+ this . setConnection ( connection ) ;
159+ let attachPromise = this . _request . isAndroid ? ( < AndroidConnection > connection ) . attach ( < number > connectionToken , 'localhost' ) : ( < IosConnection > connection ) . attach ( < string > connectionToken ) ;
160+ attachPromise . then ( ( ) => {
161+ // Send InitializedEvent
162+ this . fireEvent ( new InitializedEvent ( ) ) ;
163+ promiseResolve ( ) ;
164+ } ) ;
166165 } ) ;
167166
168- // Send InitializedEvent
169- return connectionEstablished . then ( ( ) => this . fireEvent ( new InitializedEvent ( ) ) , e => {
170- Services . logger . error ( `Error: ${ e } ` , Tags . FrontendMessage ) ;
171- this . clearEverything ( ) ;
172- return utils . errP ( e ) ;
173- } ) ;
167+ return promise ;
174168 }
175169
176170 private setConnection ( connection : INSDebugConnection ) : INSDebugConnection {
@@ -201,10 +195,12 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
201195 }
202196
203197 private terminateSession ( ) : void {
204- //this.fireEvent(new TerminatedEvent());
205-
206- Services . logger . log ( "Terminating debug session" ) ;
207198 this . clearEverything ( ) ;
199+ // In case of a sync request the session is not terminated when the backend is detached
200+ if ( ! this . _request . isSync ) {
201+ Services . logger . log ( "Terminating debug session" ) ;
202+ this . fireEvent ( new TerminatedEvent ( ) ) ;
203+ }
208204 }
209205
210206 private clearEverything ( ) : void {
0 commit comments