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" ;
2
2
import { cache } from "../common/decorators" ;
3
3
import { APPLICATION_RESPONSE_TIMEOUT_SECONDS } from "../constants" ;
4
4
5
5
export class IOSDebuggerPortService implements IIOSDebuggerPortService {
6
6
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 ( .* ) [ . ] / ;
7
7
private mapDebuggerPortData : IDictionary < IIOSDebuggerPortStoredData > = { } ;
8
+ private currentAppId : string ;
8
9
9
10
constructor ( private $logParserService : ILogParserService ,
10
11
private $iOSNotification : IiOSNotification ,
11
12
private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
12
13
private $logger : ILogger ) { }
13
14
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 ) => {
16
17
const key = `${ data . deviceId } ${ data . appId } ` ;
17
18
const retryInterval = 500 ;
18
19
let retryCount = Math . max ( APPLICATION_RESPONSE_TIMEOUT_SECONDS * 1000 / retryInterval , 10 ) ;
19
20
20
21
const interval = setInterval ( ( ) => {
21
- let port = this . getPortByKey ( key ) ;
22
+ const port = this . getPortByKey ( key ) ;
22
23
if ( port || retryCount === 0 ) {
23
24
clearInterval ( interval ) ;
24
25
resolve ( port ) ;
25
26
} 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
+ }
28
33
}
29
34
} , retryInterval ) ;
30
35
} ) ;
31
36
}
32
37
33
- public async attachToDebuggerPortFoundEvent ( ) : Promise < void > {
38
+ public async attachToDebuggerPortFoundEvent ( appId : string ) : Promise < void > {
39
+ this . currentAppId = appId ;
34
40
this . attachToDebuggerPortFoundEventCore ( ) ;
35
41
this . attachToAttachRequestEvent ( ) ;
36
42
}
@@ -43,6 +49,24 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
43
49
name : "debugPort" ,
44
50
platform : this . $devicePlatformsConstants . iOS . toLowerCase ( )
45
51
} ) ;
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 } ) ;
46
70
}
47
71
48
72
private handlePortFound ( matches : RegExpMatchArray , deviceId : string ) : void {
@@ -73,7 +97,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
73
97
}
74
98
75
99
private getPortByKey ( key : string ) : number {
76
- if ( this . mapDebuggerPortData [ key ] ) {
100
+ if ( this . mapDebuggerPortData [ key ] && this . mapDebuggerPortData [ key ] . port ) {
77
101
return this . mapDebuggerPortData [ key ] . port ;
78
102
}
79
103
@@ -89,6 +113,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
89
113
90
114
this . mapDebuggerPortData [ key ] . port = storedData . port ;
91
115
this . mapDebuggerPortData [ key ] . timer = storedData . timer ;
116
+ this . mapDebuggerPortData [ key ] . error = storedData . error ;
92
117
}
93
118
94
119
private clearTimeout ( data : IIOSDebuggerPortData ) : void {
0 commit comments