@@ -60,6 +60,8 @@ function connectEventually(factory: () => net.Socket, handler: (socket: net.Sock
6060}
6161
6262class IOSDebugService implements IDebugService {
63+ private static TIMEOUT_SECONDS = 60 ;
64+
6365 constructor (
6466 private $platformService : IPlatformService ,
6567 private $iOSEmulatorServices : Mobile . IEmulatorPlatformServices ,
@@ -73,16 +75,22 @@ class IOSDebugService implements IDebugService {
7375 private $injector : IInjector ,
7476 private $npmInstallationManager : INpmInstallationManager ,
7577 private $options : IOptions ,
76- private $projectDataService : IProjectDataService ) { }
78+ private $projectDataService : IProjectDataService ,
79+ private $utils : IUtils ) { }
7780
7881 get platform ( ) : string {
7982 return "ios" ;
8083 }
8184
8285 public debug ( ) : IFuture < void > {
83- if ( ( ! this . $options . debugBrk && ! this . $options . start ) || ( this . $options . debugBrk && this . $options . start ) ) {
86+ if ( this . $options . debugBrk && this . $options . start ) {
8487 this . $errors . failWithoutHelp ( "Expected exactly one of the --debug-brk or --start options." ) ;
8588 }
89+
90+ if ( ! this . $options . debugBrk && ! this . $options . start ) {
91+ this . $logger . warn ( "Neither --debug-brk nor --start option was specified. Defaulting to --debug-brk." ) ;
92+ this . $options . debugBrk = true ;
93+ }
8694
8795 if ( this . $options . emulator ) {
8896 if ( this . $options . debugBrk ) {
@@ -137,12 +145,14 @@ class IOSDebugService implements IDebugService {
137145 let npc = new iOSProxyServices . NotificationProxyClient ( iosDevice , this . $injector ) ;
138146
139147 try {
140- awaitNotification ( npc , notification . appLaunching ( projectId ) , 60000 ) . wait ( ) ;
148+ let timeout = this . $utils . getMilliSecondsTimeout ( IOSDebugService . TIMEOUT_SECONDS ) ;
149+ awaitNotification ( npc , notification . appLaunching ( projectId ) , timeout ) . wait ( ) ;
141150 process . nextTick ( ( ) => {
142151 npc . postNotificationAndAttachForData ( notification . waitForDebug ( projectId ) ) ;
143152 npc . postNotificationAndAttachForData ( notification . attachRequest ( projectId ) ) ;
144153 } ) ;
145- awaitNotification ( npc , notification . readyForAttach ( projectId ) , 5000 ) . wait ( ) ;
154+
155+ awaitNotification ( npc , notification . readyForAttach ( projectId ) , this . getReadyForAttachTimeout ( timeout ) ) . wait ( ) ;
146156 } catch ( e ) {
147157 this . $logger . trace ( `Timeout error: ${ e } ` ) ;
148158 this . $errors . failWithoutHelp ( "Timeout waiting for NativeScript debugger." ) ;
@@ -163,11 +173,12 @@ class IOSDebugService implements IDebugService {
163173 let projectId = this . $projectData . projectId ;
164174 let npc = new iOSProxyServices . NotificationProxyClient ( iosDevice , this . $injector ) ;
165175
176+ let timeout = this . getReadyForAttachTimeout ( ) ;
166177 let [ alreadyConnected , readyForAttach , attachAvailable ] = [
167178 notification . alreadyConnected ( projectId ) ,
168179 notification . readyForAttach ( projectId ) ,
169180 notification . attachAvailable ( projectId )
170- ] . map ( ( notification ) => awaitNotification ( npc , notification , 2000 ) ) ;
181+ ] . map ( ( notification ) => awaitNotification ( npc , notification , timeout ) ) ;
171182
172183 npc . postNotificationAndAttachForData ( notification . attachAvailabilityQuery ( projectId ) ) ;
173184
@@ -183,7 +194,7 @@ class IOSDebugService implements IDebugService {
183194 this . $errors . failWithoutHelp ( "A debugger is already connected." ) ;
184195 case attachAvailable :
185196 process . nextTick ( ( ) => npc . postNotificationAndAttachForData ( notification . attachRequest ( projectId ) ) ) ;
186- try { awaitNotification ( npc , notification . readyForAttach ( projectId ) , 2000 ) . wait ( ) ; }
197+ try { awaitNotification ( npc , notification . readyForAttach ( projectId ) , timeout ) . wait ( ) ; }
187198 catch ( e ) {
188199 this . $errors . failWithoutHelp ( `The application ${ projectId } timed out when performing the NativeScript debugger handshake.` ) ;
189200 }
@@ -244,6 +255,14 @@ class IOSDebugService implements IDebugService {
244255 return inspectorPath ;
245256 } ) . future < string > ( ) ( ) ;
246257 }
258+
259+
260+ private getReadyForAttachTimeout ( timeoutInMilliseconds ?: number ) : number {
261+ let timeout = timeoutInMilliseconds || this . $utils . getMilliSecondsTimeout ( IOSDebugService . TIMEOUT_SECONDS ) ;
262+ let readyForAttachTimeout = timeout / 10 ;
263+ let defaultReadyForAttachTimeout = 5000 ;
264+ return readyForAttachTimeout > defaultReadyForAttachTimeout ? readyForAttachTimeout : defaultReadyForAttachTimeout ;
265+ }
247266}
248267$injector . register ( "iOSDebugService" , IOSDebugService ) ;
249268
@@ -306,7 +325,7 @@ function awaitNotification(npc: iOSProxyServices.NotificationProxyClient, notifi
306325
307326 let timeoutObject = setTimeout ( ( ) => {
308327 detachObserver ( ) ;
309- future . throw ( new Error ( " Timeout receiving notification." ) ) ;
328+ future . throw ( new Error ( ` Timeout receiving ${ notification } notification.` ) ) ;
310329 } , timeout ) ;
311330
312331 function notificationObserver ( notification : string ) {
0 commit comments