@@ -137,43 +137,51 @@ export class IosProject extends NSProject {
137
137
return Promise . reject ( 'iOS platform is supported only on OS X.' ) ;
138
138
}
139
139
140
+ let rebuild = ( args . request == "launch" ) ? ( args as ILaunchRequestArgs ) . rebuild : true ;
140
141
// build command to execute
141
142
let command = new CommandBuilder ( )
142
143
. appendParam ( "debug" )
143
144
. appendParam ( this . platform ( ) )
144
145
. appendParamIf ( "--emulator" , args . emulator )
145
146
. appendParamIf ( "--start" , args . request === "attach" )
146
147
. appendParamIf ( "--debug-brk" , args . request === "launch" )
147
- . appendParamIf ( "--no-rebuild" , ! args . rebuild )
148
+ . appendParamIf ( "--no-rebuild" , ! rebuild )
148
149
. appendParam ( "--no-client" )
149
150
. appendParams ( args . tnsArgs )
150
151
. build ( ) ;
151
152
152
153
let socketPathPrefix = 'socket-file-location: ' ;
153
154
let socketPathPattern : RegExp = new RegExp ( socketPathPrefix + '.*\.sock' ) ;
154
- let readyToConnect : boolean = false ;
155
+
156
+ let isSocketOpened = ( cliOutput : string ) : string => {
157
+ let matches : RegExpMatchArray = cliOutput . match ( socketPathPattern ) ;
158
+ if ( matches && matches . length > 0 ) {
159
+ return matches [ 0 ] . substr ( socketPathPrefix . length ) ;
160
+ }
161
+ return null ;
162
+ } ;
163
+
164
+ let isAppSynced = ( cliOutput : string ) => {
165
+ return cliOutput . indexOf ( 'Successfully synced application' ) > - 1 ;
166
+ } ;
155
167
156
168
return new Promise < string > ( ( resolve , reject ) => {
157
169
// run NativeScript CLI command
158
170
let child : ChildProcess = this . spawnProcess ( command . path , command . args , args . tnsOutput ) ;
159
- let synced = false ;
171
+
172
+ let appSynced = false ;
173
+ let socketPath : string = null ;
160
174
161
175
child . stdout . on ( 'data' , ( data ) => {
162
- let strData : string = data . toString ( ) ;
163
- this . emit ( 'TNS.outputMessage' , strData , 'log' ) ;
164
- this . writeToTnsOutputFile ( strData ) ;
165
- if ( ! synced && ! args . rebuild && strData . indexOf ( 'Successfully synced application' ) > - 1 ) {
166
- synced = true ;
167
- //wait a little before trying to connect, this gives a changes for adb to be able to connect to the debug socket
168
- setTimeout ( ( ) => {
169
- resolve ( ) ;
170
- } , 500 ) ;
171
- } else if ( ! readyToConnect ) {
172
- let matches : RegExpMatchArray = strData . match ( socketPathPattern ) ;
173
- if ( matches && matches . length > 0 ) {
174
- readyToConnect = true ;
175
- resolve ( matches [ 0 ] . substr ( socketPathPrefix . length ) ) ;
176
- }
176
+ let cliOutput : string = data . toString ( ) ;
177
+ this . emit ( 'TNS.outputMessage' , cliOutput , 'log' ) ;
178
+ this . writeToTnsOutputFile ( cliOutput ) ;
179
+
180
+ socketPath = socketPath || isSocketOpened ( cliOutput ) ;
181
+ appSynced = rebuild ? false : ( appSynced || isAppSynced ( cliOutput ) ) ;
182
+
183
+ if ( ( rebuild && socketPath ) || ( ! rebuild && socketPath && appSynced ) ) {
184
+ resolve ( socketPath ) ;
177
185
}
178
186
} ) ;
179
187
@@ -183,13 +191,7 @@ export class IosProject extends NSProject {
183
191
} ) ;
184
192
185
193
child . on ( 'close' , ( code , signal ) => {
186
- if ( ! args . rebuild ) {
187
- setTimeout ( ( ) => {
188
- reject ( "The debug process exited unexpectedly code:" + code ) ;
189
- } , 3000 ) ;
190
- } else {
191
- reject ( "The debug process exited unexpectedly code:" + code ) ;
192
- }
194
+ reject ( "The debug process exited unexpectedly code:" + code ) ;
193
195
} ) ;
194
196
} ) ;
195
197
}
@@ -221,11 +223,12 @@ export class AndroidProject extends NSProject {
221
223
return Promise . resolve ( child ) ;
222
224
}
223
225
224
- public debug ( args : IAttachRequestArgs | ILaunchRequestArgs ) : Promise < void > {
225
- if ( args . request === "attach" ) {
226
+ public debug ( params : IAttachRequestArgs | ILaunchRequestArgs ) : Promise < void > {
227
+ if ( params . request === "attach" ) {
226
228
return Promise . resolve < void > ( ) ;
227
229
}
228
- else if ( args . request === "launch" ) {
230
+ else if ( params . request === "launch" ) {
231
+ let args : ILaunchRequestArgs = params as ILaunchRequestArgs ;
229
232
let that = this ;
230
233
let launched = false ;
231
234
0 commit comments