@@ -15,13 +15,13 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
15
15
public async install ( ipaPath : string , deviceIdentifiers : string [ ] , errorHandler : DeviceOperationErrorHandler ) : Promise < IOSDeviceResponse > {
16
16
this . assertIsInitialized ( ) ;
17
17
this . $logger . trace ( `Installing ${ ipaPath } on devices with identifiers: ${ deviceIdentifiers } .` ) ;
18
- return await this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . install ( ipaPath , deviceIdentifiers ) , deviceIdentifiers , errorHandler ) ;
18
+ return await this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . install ( ipaPath , deviceIdentifiers ) , errorHandler ) ;
19
19
}
20
20
21
21
public async uninstall ( appIdentifier : string , deviceIdentifiers : string [ ] , errorHandler : DeviceOperationErrorHandler ) : Promise < IOSDeviceResponse > {
22
22
this . assertIsInitialized ( ) ;
23
23
this . $logger . trace ( `Uninstalling ${ appIdentifier } from devices with identifiers: ${ deviceIdentifiers } .` ) ;
24
- return await this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . uninstall ( appIdentifier , deviceIdentifiers ) , deviceIdentifiers , errorHandler ) ;
24
+ return await this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . uninstall ( appIdentifier , deviceIdentifiers ) , errorHandler ) ;
25
25
}
26
26
27
27
@cache ( )
@@ -38,7 +38,6 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
38
38
}
39
39
}
40
40
41
- @cache ( )
42
41
public startDeviceLog ( deviceIdentifier : string , printLogFunction : ( data : string ) => void ) : void {
43
42
this . assertIsInitialized ( ) ;
44
43
this . setShouldDispose ( false ) ;
@@ -55,7 +54,7 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
55
54
public async apps ( deviceIdentifiers : string [ ] , errorHandler ?: DeviceOperationErrorHandler ) : Promise < IOSDeviceAppInfo > {
56
55
this . assertIsInitialized ( ) ;
57
56
this . $logger . trace ( `Getting applications information for devices with identifiers: ${ deviceIdentifiers } ` ) ;
58
- return this . getMultipleResults ( ( ) => this . deviceLib . apps ( deviceIdentifiers ) , deviceIdentifiers , errorHandler ) ;
57
+ return this . getMultipleResults ( ( ) => this . deviceLib . apps ( deviceIdentifiers ) , errorHandler ) ;
59
58
}
60
59
61
60
public async listDirectory ( listArray : IOSDeviceLib . IReadOperationData [ ] , errorHandler ?: DeviceOperationErrorHandler ) : Promise < IOSDeviceMultipleResponse > {
@@ -65,7 +64,7 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
65
64
this . $logger . trace ( `Listing directory: ${ l . path } for application ${ l . appId } on device with identifier: ${ l . deviceId } .` ) ;
66
65
} ) ;
67
66
68
- return this . getMultipleResults < IOSDeviceLib . IDeviceMultipleResponse > ( ( ) => this . deviceLib . list ( listArray ) , this . getDeviceIdentifiersArray ( listArray ) , errorHandler ) ;
67
+ return this . getMultipleResults < IOSDeviceLib . IDeviceMultipleResponse > ( ( ) => this . deviceLib . list ( listArray ) , errorHandler ) ;
69
68
}
70
69
71
70
public async readFiles ( deviceFilePaths : IOSDeviceLib . IReadOperationData [ ] , errorHandler ?: DeviceOperationErrorHandler ) : Promise < IOSDeviceResponse > {
@@ -75,7 +74,7 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
75
74
this . $logger . trace ( `Reading file: ${ p . path } from application ${ p . appId } on device with identifier: ${ p . deviceId } .` ) ;
76
75
} ) ;
77
76
78
- return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . read ( deviceFilePaths ) , this . getDeviceIdentifiersArray ( deviceFilePaths ) , errorHandler ) ;
77
+ return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . read ( deviceFilePaths ) , errorHandler ) ;
79
78
}
80
79
81
80
public async downloadFiles ( deviceFilePaths : IOSDeviceLib . IFileOperationData [ ] , errorHandler ?: DeviceOperationErrorHandler ) : Promise < IOSDeviceResponse > {
@@ -85,10 +84,10 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
85
84
this . $logger . trace ( `Downloading file: ${ d . source } from application ${ d . appId } on device with identifier: ${ d . deviceId } to ${ d . destination } .` ) ;
86
85
} ) ;
87
86
88
- return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . download ( deviceFilePaths ) , this . getDeviceIdentifiersArray ( deviceFilePaths ) , errorHandler ) ;
87
+ return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . download ( deviceFilePaths ) , errorHandler ) ;
89
88
}
90
89
91
- public uploadFiles ( files : IOSDeviceLib . IUploadFilesData [ ] ) : Promise < IOSDeviceLib . IDeviceResponse > [ ] {
90
+ public uploadFiles ( files : IOSDeviceLib . IUploadFilesData [ ] , errorHandler ?: DeviceOperationErrorHandler ) : Promise < IOSDeviceResponse > {
92
91
this . assertIsInitialized ( ) ;
93
92
94
93
_ . each ( files , f => {
@@ -97,7 +96,7 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
97
96
this . $logger . trace ( `For application ${ f . appId } on device with identifier: ${ f . deviceId } .` ) ;
98
97
} ) ;
99
98
100
- return this . deviceLib . upload ( files ) ;
99
+ return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . upload ( files ) , errorHandler ) ;
101
100
}
102
101
103
102
public async deleteFiles ( deleteArray : IOSDeviceLib . IDeleteFileData [ ] , errorHandler ?: DeviceOperationErrorHandler ) : Promise < IOSDeviceResponse > {
@@ -107,7 +106,7 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
107
106
this . $logger . trace ( `Deleting file: ${ d . destination } from application ${ d . appId } on device with identifier: ${ d . deviceId } .` ) ;
108
107
} ) ;
109
108
110
- return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . delete ( deleteArray ) , this . getDeviceIdentifiersArray ( deleteArray ) , errorHandler ) ;
109
+ return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . delete ( deleteArray ) , errorHandler ) ;
111
110
}
112
111
113
112
public async start ( startArray : IOSDeviceLib . IDdiApplicationData [ ] , errorHandler ?: DeviceOperationErrorHandler ) : Promise < IOSDeviceResponse > {
@@ -117,7 +116,7 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
117
116
this . $logger . trace ( `Starting application ${ s . appId } on device with identifier: ${ s . deviceId } .` ) ;
118
117
} ) ;
119
118
120
- return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . start ( startArray ) , this . getDeviceIdentifiersArray ( startArray ) , errorHandler ) ;
119
+ return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . start ( startArray ) , errorHandler ) ;
121
120
}
122
121
123
122
public async stop ( stopArray : IOSDeviceLib . IDdiApplicationData [ ] , errorHandler ?: DeviceOperationErrorHandler ) : Promise < IOSDeviceResponse > {
@@ -127,7 +126,7 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
127
126
this . $logger . trace ( `Stopping application ${ s . appId } on device with identifier: ${ s . deviceId } .` ) ;
128
127
} ) ;
129
128
130
- return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . start ( stopArray ) , this . getDeviceIdentifiersArray ( stopArray ) , errorHandler ) ;
129
+ return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . start ( stopArray ) , errorHandler ) ;
131
130
}
132
131
133
132
public dispose ( signal ?: string ) : void {
@@ -147,7 +146,7 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
147
146
this . $logger . trace ( `Sending notification ${ n . notificationName } to device with identifier: ${ n . deviceId } ` ) ;
148
147
} ) ;
149
148
150
- return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . notify ( notifyArray ) , this . getDeviceIdentifiersArray ( notifyArray ) , errorHandler ) ;
149
+ return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . notify ( notifyArray ) , errorHandler ) ;
151
150
}
152
151
153
152
public async connectToPort ( connectToPortArray : IOSDeviceLib . IConnectToPortData [ ] , errorHandler ?: DeviceOperationErrorHandler ) : Promise < IOSDeviceResponse > {
@@ -157,26 +156,24 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
157
156
this . $logger . trace ( `Connecting to port ${ c . port } on device with identifier: ${ c . deviceId } ` ) ;
158
157
} ) ;
159
158
160
- return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . connectToPort ( connectToPortArray ) , this . getDeviceIdentifiersArray ( connectToPortArray ) , errorHandler ) ;
159
+ return this . getMultipleResults < IOSDeviceLib . IDeviceResponse > ( ( ) => this . deviceLib . connectToPort ( connectToPortArray ) , errorHandler ) ;
161
160
}
162
161
163
162
public setShouldDispose ( shouldDispose : boolean ) : void {
164
163
this . shouldDispose = shouldDispose ;
165
164
}
166
165
167
- private async getMultipleResults < T > ( getPromisesMethod : ( ) => Promise < T > [ ] , deviceIdentifiers : string [ ] , errorHandler ?: DeviceOperationErrorHandler ) : Promise < IDictionary < T [ ] > > {
166
+ private async getMultipleResults < T > ( getPromisesMethod : ( ) => Promise < T > [ ] , errorHandler ?: DeviceOperationErrorHandler ) : Promise < IDictionary < T [ ] > > {
168
167
const result : T [ ] = [ ] ;
169
168
const promises = getPromisesMethod ( ) ;
170
169
171
- for ( let i = 0 ; i < promises . length ; i ++ ) {
172
- const promise = promises [ i ] ;
173
-
170
+ for ( let promise of promises ) {
174
171
if ( errorHandler ) {
175
172
try {
176
173
result . push ( await promise ) ;
177
174
} catch ( err ) {
178
175
this . $logger . trace ( `Error while executing ios device operation: ${ err . message } with code: ${ err . code } ` ) ;
179
- errorHandler ( { error : err , deviceIdentifier : deviceIdentifiers [ i ] } ) ;
176
+ errorHandler ( err ) ;
180
177
}
181
178
} else {
182
179
result . push ( await promise ) ;
@@ -186,10 +183,6 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
186
183
return _ . groupBy ( result , r => ( < any > r ) . deviceId ) ;
187
184
}
188
185
189
- private getDeviceIdentifiersArray ( deviceInformation : IOSDeviceLib . IDeviceId [ ] ) : string [ ] {
190
- return _ . map ( deviceInformation , d => d . deviceId ) ;
191
- }
192
-
193
186
private assertIsInitialized ( ) : void {
194
187
assert . ok ( this . isInitialized , "iOS device operations not initialized." ) ;
195
188
}
0 commit comments