@@ -60,16 +60,22 @@ export class DevicesService implements Mobile.IDevicesService {
60
60
}
61
61
62
62
public isiOSSimulator ( device : Mobile . IDevice ) : boolean {
63
- return this . $mobileHelper . isiOSPlatform ( device . deviceInfo . platform ) && device . isEmulator ;
63
+ return ! ! ( this . $mobileHelper . isiOSPlatform ( device . deviceInfo . platform ) && device . isEmulator ) ;
64
64
}
65
65
66
66
/* tslint:disable:no-unused-variable */
67
67
@exported ( "devicesService" )
68
- private setLogLevel ( logLevel : string , deviceIdentifier ?: string ) : void {
68
+ public setLogLevel ( logLevel : string , deviceIdentifier ?: string ) : void {
69
69
this . $deviceLogProvider . setLogLevel ( logLevel , deviceIdentifier ) ;
70
70
}
71
71
/* tslint:enable:no-unused-variable */
72
72
73
+ @exportedPromise ( "devicesService" )
74
+ public isAppInstalledOnDevices ( deviceIdentifiers : string [ ] , appIdentifier : string ) : IFuture < boolean > [ ] {
75
+ this . $logger . trace ( `Called isInstalledOnDevices for identifiers ${ deviceIdentifiers } . AppIdentifier is ${ appIdentifier } .` ) ;
76
+ return _ . map ( deviceIdentifiers , deviceIdentifier => this . isApplicationInstalledOnDevice ( deviceIdentifier , appIdentifier ) ) ;
77
+ }
78
+
73
79
public getDeviceInstances ( ) : Mobile . IDevice [ ] {
74
80
return _ . values ( this . _devices ) ;
75
81
}
@@ -210,9 +216,7 @@ export class DevicesService implements Mobile.IDevicesService {
210
216
211
217
let futures = _ . map ( sortedDevices , ( device : Mobile . IDevice ) => {
212
218
if ( ! canExecute || canExecute ( device ) ) {
213
- let future = action ( device ) ;
214
- Future . settle ( future ) ;
215
- return future ;
219
+ return action ( device ) ;
216
220
} else {
217
221
return Future . fromResult ( ) ;
218
222
}
@@ -235,7 +239,9 @@ export class DevicesService implements Mobile.IDevicesService {
235
239
if ( this . $hostInfo . isDarwin && this . _platform && this . $mobileHelper . isiOSPlatform ( this . _platform ) &&
236
240
this . $options . emulator && ! this . isOnlyiOSSimultorRunning ( ) ) {
237
241
this . startEmulator ( ) . wait ( ) ;
238
- canExecute = ( dev : Mobile . IDevice ) : boolean => this . isiOSSimulator ( dev ) ; // Executes the command only on iOS simulator
242
+ // Executes the command only on iOS simulator
243
+ let originalCanExecute = canExecute ;
244
+ canExecute = ( dev : Mobile . IDevice ) : boolean => this . isiOSSimulator ( dev ) && ( ! originalCanExecute || ! ! ( originalCanExecute ( dev ) ) ) ;
239
245
}
240
246
this . executeCore ( action , canExecute ) . wait ( ) ;
241
247
} else {
@@ -278,11 +284,23 @@ export class DevicesService implements Mobile.IDevicesService {
278
284
} else if ( platform && ! deviceOption ) {
279
285
this . _platform = this . getPlatform ( platform ) ;
280
286
this . startLookingForDevices ( ) . wait ( ) ;
281
- } else if ( ! platform && ! deviceOption ) {
287
+ } else {
288
+ // platform and deviceId are not specified
282
289
this . startLookingForDevices ( ) . wait ( ) ;
283
290
if ( ! data . skipInferPlatform ) {
284
291
let devices = this . getDeviceInstances ( ) ;
285
- let platforms = _ . uniq ( _ . map ( devices , ( device ) => device . deviceInfo . platform ) ) ;
292
+ let platforms = _ ( devices )
293
+ . map ( device => device . deviceInfo . platform )
294
+ . filter ( pl => {
295
+ try {
296
+ return this . getPlatform ( pl ) ;
297
+ } catch ( err ) {
298
+ this . $logger . warn ( err . message ) ;
299
+ return null ;
300
+ }
301
+ } )
302
+ . uniq ( )
303
+ . value ( ) ;
286
304
287
305
if ( platforms . length === 1 ) {
288
306
this . _platform = platforms [ 0 ] ;
@@ -296,7 +314,7 @@ export class DevicesService implements Mobile.IDevicesService {
296
314
}
297
315
298
316
if ( ! this . $hostInfo . isDarwin && this . _platform && this . $mobileHelper . isiOSPlatform ( this . _platform ) && this . $options . emulator ) {
299
- this . $errors . failWithoutHelp ( "You are not allowed to use iOS simulator on Windows ." ) ;
317
+ this . $errors . failWithoutHelp ( "You can use iOS simulator only on OS X ." ) ;
300
318
}
301
319
this . _isInitialized = true ;
302
320
} ) . future < void > ( ) ( ) ;
@@ -321,19 +339,15 @@ export class DevicesService implements Mobile.IDevicesService {
321
339
322
340
private deployOnDevice ( deviceIdentifier : string , packageFile : string , packageName : string ) : IFuture < void > {
323
341
return ( ( ) => {
324
- if ( _ ( this . _devices ) . keys ( ) . find ( d => d === deviceIdentifier ) ) {
325
- let device = this . _devices [ deviceIdentifier ] ;
326
- device . applicationManager . reinstallApplication ( packageName , packageFile ) . wait ( ) ;
327
- this . $logger . info ( `Successfully deployed on device with identifier '${ device . deviceInfo . identifier } '.` ) ;
328
- if ( device . applicationManager . canStartApplication ( ) ) {
329
- try {
330
- device . applicationManager . startApplication ( packageName ) . wait ( ) ;
331
- } catch ( err ) {
332
- this . $logger . trace ( "Unable to start application on device. Error is: " , err ) ;
333
- }
342
+ let device = this . getDeviceByIdentifier ( deviceIdentifier ) ;
343
+ device . applicationManager . reinstallApplication ( packageName , packageFile ) . wait ( ) ;
344
+ this . $logger . info ( `Successfully deployed on device with identifier '${ device . deviceInfo . identifier } '.` ) ;
345
+ if ( device . applicationManager . canStartApplication ( ) ) {
346
+ try {
347
+ device . applicationManager . startApplication ( packageName ) . wait ( ) ;
348
+ } catch ( err ) {
349
+ this . $logger . trace ( "Unable to start application on device. Error is: " , err ) ;
334
350
}
335
- } else {
336
- throw new Error ( `Cannot find device with identifier ${ deviceIdentifier } .` ) ;
337
351
}
338
352
} ) . future < void > ( ) ( ) ;
339
353
}
@@ -358,11 +372,16 @@ export class DevicesService implements Mobile.IDevicesService {
358
372
} else if ( this . $mobileHelper . isAndroidPlatform ( this . _platform ) ) {
359
373
return this . $injector . resolve ( "androidEmulatorServices" ) ;
360
374
}
375
+
376
+ return null ;
361
377
}
362
378
363
379
private startEmulator ( ) : IFuture < void > {
364
380
return ( ( ) => {
365
381
let emulatorServices = this . resolveEmulatorServices ( ) ;
382
+ if ( ! emulatorServices ) {
383
+ this . $errors . failWithoutHelp ( "Unable to detect platform for which to start emulator." ) ;
384
+ }
366
385
emulatorServices . startEmulator ( ) . wait ( ) ;
367
386
if ( this . $mobileHelper . isAndroidPlatform ( this . _platform ) ) {
368
387
this . $androidDeviceDiscovery . checkForDevices ( ) . wait ( ) ;
@@ -378,6 +397,13 @@ export class DevicesService implements Mobile.IDevicesService {
378
397
}
379
398
380
399
return this . executeOnAllConnectedDevices ( action , canExecute ) ;
400
+ }
401
+
402
+ private isApplicationInstalledOnDevice ( deviceIdentifier : string , appIdentifier : string ) : IFuture < boolean > {
403
+ return ( ( ) : boolean => {
404
+ let device = this . getDeviceByIdentifier ( deviceIdentifier ) ;
405
+ return device . applicationManager . isApplicationInstalled ( appIdentifier ) . wait ( ) ;
406
+ } ) . future < boolean > ( ) ( ) ;
381
407
}
382
408
}
383
409
0 commit comments