|
2 | 2 | "use strict"; |
3 | 3 |
|
4 | 4 | export class DebugPlatformCommand implements ICommand { |
5 | | - constructor(private debugService: IDebugService) { } |
| 5 | + constructor(private debugService: IDebugService, |
| 6 | + private $devicesService: Mobile.IDevicesService, |
| 7 | + private $errors: IErrors, |
| 8 | + protected $options: IOptions) { } |
6 | 9 |
|
7 | 10 | execute(args: string[]): IFuture<void> { |
8 | 11 | return this.debugService.debug(); |
9 | 12 | } |
10 | 13 |
|
11 | 14 | allowedParameters: ICommandParameter[] = []; |
| 15 | + |
| 16 | + canExecute(args: string[]): IFuture<boolean> { |
| 17 | + return ((): boolean => { |
| 18 | + this.$devicesService.initialize({ platform: this.debugService.platform, deviceId: this.$options.device }).wait(); |
| 19 | + if(this.$devicesService.deviceCount === 0) { |
| 20 | + this.$errors.failWithoutHelp("No devices detected. Connect a device and try again."); |
| 21 | + } else if (this.$devicesService.deviceCount > 1) { |
| 22 | + this.$errors.fail("Cannot debug on multiple devices. Select device with --device option."); |
| 23 | + } |
| 24 | + |
| 25 | + return true; |
| 26 | + }).future<boolean>()(); |
| 27 | + } |
12 | 28 | } |
13 | 29 |
|
14 | 30 | export class DebugIOSCommand extends DebugPlatformCommand { |
15 | | - constructor(private $iOSDebugService: IDebugService) { |
16 | | - super($iOSDebugService); |
| 31 | + constructor($iOSDebugService: IDebugService, |
| 32 | + $devicesService: Mobile.IDevicesService, |
| 33 | + $errors: IErrors, |
| 34 | + $options: IOptions) { |
| 35 | + super($iOSDebugService, $devicesService, $errors, $options); |
| 36 | + } |
| 37 | + |
| 38 | + canExecute(args: string[]): IFuture<boolean> { |
| 39 | + return ((): boolean => { |
| 40 | + if(this.$options.emulator) { |
| 41 | + return true; |
| 42 | + } |
| 43 | + |
| 44 | + return super.canExecute(args).wait(); |
| 45 | + }).future<boolean>()(); |
17 | 46 | } |
18 | 47 | } |
19 | 48 | $injector.registerCommand("debug|ios", DebugIOSCommand); |
20 | 49 |
|
21 | 50 | export class DebugAndroidCommand extends DebugPlatformCommand { |
22 | | - constructor(private $androidDebugService: IDebugService) { |
23 | | - super($androidDebugService); |
| 51 | + constructor($androidDebugService: IDebugService, |
| 52 | + $devicesService: Mobile.IDevicesService, |
| 53 | + $errors: IErrors, |
| 54 | + $options: IOptions) { |
| 55 | + super($androidDebugService, $devicesService, $errors, $options); |
| 56 | + } |
| 57 | + |
| 58 | + canExecute(args: string[]): IFuture<boolean> { |
| 59 | + return super.canExecute(args); |
24 | 60 | } |
25 | 61 | } |
26 | 62 | $injector.registerCommand("debug|android", DebugAndroidCommand); |
0 commit comments