@@ -60,6 +60,8 @@ function connectEventually(factory: () => net.Socket, handler: (socket: net.Sock
60
60
}
61
61
62
62
class IOSDebugService implements IDebugService {
63
+ private static TIMEOUT_SECONDS = 60 ;
64
+
63
65
constructor (
64
66
private $platformService : IPlatformService ,
65
67
private $iOSEmulatorServices : Mobile . IEmulatorPlatformServices ,
@@ -73,16 +75,22 @@ class IOSDebugService implements IDebugService {
73
75
private $injector : IInjector ,
74
76
private $npmInstallationManager : INpmInstallationManager ,
75
77
private $options : IOptions ,
76
- private $projectDataService : IProjectDataService ) { }
78
+ private $projectDataService : IProjectDataService ,
79
+ private $utils : IUtils ) { }
77
80
78
81
get platform ( ) : string {
79
82
return "ios" ;
80
83
}
81
84
82
85
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 ) {
84
87
this . $errors . failWithoutHelp ( "Expected exactly one of the --debug-brk or --start options." ) ;
85
88
}
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
+ }
86
94
87
95
if ( this . $options . emulator ) {
88
96
if ( this . $options . debugBrk ) {
@@ -137,12 +145,14 @@ class IOSDebugService implements IDebugService {
137
145
let npc = new iOSProxyServices . NotificationProxyClient ( iosDevice , this . $injector ) ;
138
146
139
147
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 ( ) ;
141
150
process . nextTick ( ( ) => {
142
151
npc . postNotificationAndAttachForData ( notification . waitForDebug ( projectId ) ) ;
143
152
npc . postNotificationAndAttachForData ( notification . attachRequest ( projectId ) ) ;
144
153
} ) ;
145
- awaitNotification ( npc , notification . readyForAttach ( projectId ) , 5000 ) . wait ( ) ;
154
+
155
+ awaitNotification ( npc , notification . readyForAttach ( projectId ) , this . getReadyForAttachTimeout ( timeout ) ) . wait ( ) ;
146
156
} catch ( e ) {
147
157
this . $logger . trace ( `Timeout error: ${ e } ` ) ;
148
158
this . $errors . failWithoutHelp ( "Timeout waiting for NativeScript debugger." ) ;
@@ -163,11 +173,12 @@ class IOSDebugService implements IDebugService {
163
173
let projectId = this . $projectData . projectId ;
164
174
let npc = new iOSProxyServices . NotificationProxyClient ( iosDevice , this . $injector ) ;
165
175
176
+ let timeout = this . getReadyForAttachTimeout ( ) ;
166
177
let [ alreadyConnected , readyForAttach , attachAvailable ] = [
167
178
notification . alreadyConnected ( projectId ) ,
168
179
notification . readyForAttach ( projectId ) ,
169
180
notification . attachAvailable ( projectId )
170
- ] . map ( ( notification ) => awaitNotification ( npc , notification , 2000 ) ) ;
181
+ ] . map ( ( notification ) => awaitNotification ( npc , notification , timeout ) ) ;
171
182
172
183
npc . postNotificationAndAttachForData ( notification . attachAvailabilityQuery ( projectId ) ) ;
173
184
@@ -183,7 +194,7 @@ class IOSDebugService implements IDebugService {
183
194
this . $errors . failWithoutHelp ( "A debugger is already connected." ) ;
184
195
case attachAvailable :
185
196
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 ( ) ; }
187
198
catch ( e ) {
188
199
this . $errors . failWithoutHelp ( `The application ${ projectId } timed out when performing the NativeScript debugger handshake.` ) ;
189
200
}
@@ -244,6 +255,14 @@ class IOSDebugService implements IDebugService {
244
255
return inspectorPath ;
245
256
} ) . future < string > ( ) ( ) ;
246
257
}
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
+ }
247
266
}
248
267
$injector . register ( "iOSDebugService" , IOSDebugService ) ;
249
268
@@ -306,7 +325,7 @@ function awaitNotification(npc: iOSProxyServices.NotificationProxyClient, notifi
306
325
307
326
let timeoutObject = setTimeout ( ( ) => {
308
327
detachObserver ( ) ;
309
- future . throw ( new Error ( " Timeout receiving notification." ) ) ;
328
+ future . throw ( new Error ( ` Timeout receiving ${ notification } notification.` ) ) ;
310
329
} , timeout ) ;
311
330
312
331
function notificationObserver ( notification : string ) {
0 commit comments