1- import { DEBUGGER_PORT_FOUND_EVENT_NAME , ATTACH_REQUEST_EVENT_NAME } from "../common/constants" ;
1+ import { DEBUGGER_PORT_FOUND_EVENT_NAME , ATTACH_REQUEST_EVENT_NAME , IOS_APP_CRASH_LOG_REG_EXP } from "../common/constants" ;
22import { cache } from "../common/decorators" ;
33import { APPLICATION_RESPONSE_TIMEOUT_SECONDS } from "../constants" ;
44
55export class IOSDebuggerPortService implements IIOSDebuggerPortService {
66 public static DEBUG_PORT_LOG_REGEX = / N a t i v e S c r i p t d e b u g g e r h a s o p e n e d i n s p e c t o r s o c k e t o n p o r t ( \d + ?) f o r ( .* ) [ . ] / ;
77 private mapDebuggerPortData : IDictionary < IIOSDebuggerPortStoredData > = { } ;
8+ private currentAppId : string ;
89
910 constructor ( private $logParserService : ILogParserService ,
1011 private $iOSNotification : IiOSNotification ,
1112 private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
1213 private $logger : ILogger ) { }
1314
14- public getPort ( data : IIOSDebuggerPortInputData ) : Promise < number > {
15- return new Promise ( ( resolve , reject ) => {
15+ public async getPort ( data : IIOSDebuggerPortInputData ) : Promise < number > {
16+ return new Promise < number > ( ( resolve , reject ) => {
1617 const key = `${ data . deviceId } ${ data . appId } ` ;
1718 const retryInterval = 500 ;
1819 let retryCount = Math . max ( APPLICATION_RESPONSE_TIMEOUT_SECONDS * 1000 / retryInterval , 10 ) ;
1920
2021 const interval = setInterval ( ( ) => {
21- let port = this . getPortByKey ( key ) ;
22+ const port = this . getPortByKey ( key ) ;
2223 if ( port || retryCount === 0 ) {
2324 clearInterval ( interval ) ;
2425 resolve ( port ) ;
2526 } else {
26- port = this . getPortByKey ( key ) ;
27- retryCount -- ;
27+ if ( this . mapDebuggerPortData [ key ] && this . mapDebuggerPortData [ key ] . error ) {
28+ clearInterval ( interval ) ;
29+ reject ( this . mapDebuggerPortData [ key ] . error ) ;
30+ } else {
31+ retryCount -- ;
32+ }
2833 }
2934 } , retryInterval ) ;
3035 } ) ;
3136 }
3237
33- public async attachToDebuggerPortFoundEvent ( ) : Promise < void > {
38+ public async attachToDebuggerPortFoundEvent ( appId : string ) : Promise < void > {
39+ this . currentAppId = appId ;
3440 this . attachToDebuggerPortFoundEventCore ( ) ;
3541 this . attachToAttachRequestEvent ( ) ;
3642 }
@@ -43,6 +49,24 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
4349 name : "debugPort" ,
4450 platform : this . $devicePlatformsConstants . iOS . toLowerCase ( )
4551 } ) ;
52+ this . $logParserService . addParseRule ( {
53+ regex : IOS_APP_CRASH_LOG_REG_EXP ,
54+ handler : this . handleAppCrash . bind ( this ) ,
55+ name : "appCrash" ,
56+ platform : this . $devicePlatformsConstants . iOS . toLowerCase ( )
57+ } ) ;
58+ }
59+
60+ private handleAppCrash ( matches : RegExpMatchArray , deviceId : string ) : void {
61+ const data = {
62+ port : 0 ,
63+ appId : this . currentAppId ,
64+ deviceId,
65+ error : new Error ( "The application has been terminated." )
66+ } ;
67+
68+ this . clearTimeout ( data ) ;
69+ this . setData ( data , { port : data . port , error : data . error } ) ;
4670 }
4771
4872 private handlePortFound ( matches : RegExpMatchArray , deviceId : string ) : void {
@@ -73,7 +97,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
7397 }
7498
7599 private getPortByKey ( key : string ) : number {
76- if ( this . mapDebuggerPortData [ key ] ) {
100+ if ( this . mapDebuggerPortData [ key ] && this . mapDebuggerPortData [ key ] . port ) {
77101 return this . mapDebuggerPortData [ key ] . port ;
78102 }
79103
@@ -89,6 +113,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
89113
90114 this . mapDebuggerPortData [ key ] . port = storedData . port ;
91115 this . mapDebuggerPortData [ key ] . timer = storedData . timer ;
116+ this . mapDebuggerPortData [ key ] . error = storedData . error ;
92117 }
93118
94119 private clearTimeout ( data : IIOSDebuggerPortData ) : void {
0 commit comments