@@ -63,6 +63,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
63
63
this . _scriptsById = new Map < WebKitProtocol . Debugger . ScriptId , WebKitProtocol . Debugger . Script > ( ) ;
64
64
this . _committedBreakpointsByUrl = new Map < string , WebKitProtocol . Debugger . BreakpointId [ ] > ( ) ;
65
65
this . _setBreakpointsRequestQ = Promise . resolve < void > ( ) ;
66
+ this . _lastOutputEvent = null ;
66
67
this . fireEvent ( { seq : 0 , type : 'event' , event : 'clearTargetContext' } ) ;
67
68
}
68
69
@@ -121,7 +122,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
121
122
Services . logger . log ( `${ args . request } (${ JSON . stringify ( args ) } )` ) ;
122
123
}
123
124
124
- private processRequest ( args : DebugProtocol . IRequestArgs ) {
125
+ private processRequest ( args : DebugProtocol . IRequestArgs ) : Promise < void > {
125
126
this . configureLoggingForRequest ( args ) ;
126
127
// Initialize the request
127
128
Services . appRoot = args . appRoot ;
@@ -147,30 +148,23 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
147
148
cliCommand . tnsProcess . on ( 'close' , ( code , signal ) => { Services . logger . error ( `The tns command finished its execution with code ${ code } .` , Tags . FrontendMessage ) ; } ) ;
148
149
}
149
150
151
+ let promiseResolve = null ;
152
+ let promise : Promise < void > = new Promise < void > ( ( res , rej ) => { promiseResolve = res ; } ) ;
150
153
// 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
+ } ) ;
166
165
} ) ;
167
166
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 ;
174
168
}
175
169
176
170
private setConnection ( connection : INSDebugConnection ) : INSDebugConnection {
@@ -201,10 +195,12 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
201
195
}
202
196
203
197
private terminateSession ( ) : void {
204
- //this.fireEvent(new TerminatedEvent());
205
-
206
- Services . logger . log ( "Terminating debug session" ) ;
207
198
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
+ }
208
204
}
209
205
210
206
private clearEverything ( ) : void {
0 commit comments