@@ -9,6 +9,7 @@ import { RunOnDevicesController } from "./run-on-devices-controller";
99import { RunOnDevicesDataService } from "../services/run-on-devices-data-service" ;
1010import { cache } from "../common/decorators" ;
1111import { DeviceDiscoveryEventNames } from "../common/constants" ;
12+ import { RunOnDevicesEmitter } from "../run-on-devices-emitter" ;
1213
1314export class MainController extends EventEmitter {
1415 constructor (
@@ -25,6 +26,7 @@ export class MainController extends EventEmitter {
2526 private $projectDataService : IProjectDataService ,
2627 private $runOnDevicesController : RunOnDevicesController ,
2728 private $runOnDevicesDataService : RunOnDevicesDataService ,
29+ private $runOnDevicesEmitter : RunOnDevicesEmitter ,
2830 private $workflowDataService : WorkflowDataService
2931 ) { super ( ) ; }
3032
@@ -146,7 +148,7 @@ export class MainController extends EventEmitter {
146148
147149 // Emit RunOnDevice stopped when we've really stopped.
148150 _ . each ( removedDeviceIdentifiers , deviceIdentifier => {
149- this . emit ( RunOnDeviceEvents . runOnDeviceStopped , { projectDir, deviceIdentifier } ) ;
151+ this . $runOnDevicesEmitter . emitRunOnDeviceStoppedEvent ( projectDir , deviceIdentifier ) ;
150152 } ) ;
151153 }
152154 }
@@ -157,13 +159,8 @@ export class MainController extends EventEmitter {
157159
158160 private handleRunOnDeviceEvents ( projectDir : string ) : void {
159161 this . $runOnDevicesController . on ( RunOnDeviceEvents . runOnDeviceError , async data => {
160- this . emit ( RunOnDeviceEvents . runOnDeviceError , data ) ;
161162 await this . stopRunOnDevices ( projectDir , [ data . deviceIdentifier ] , { shouldAwaitAllActions : false } ) ;
162163 } ) ;
163-
164- this . $runOnDevicesController . on ( RunOnDeviceEvents . runOnDeviceStarted , data => {
165- this . emit ( RunOnDeviceEvents . runOnDeviceStarted , data ) ;
166- } ) ;
167164 }
168165
169166 // TODO: expose previewOnDevice() method { }
@@ -190,15 +187,16 @@ export class MainController extends EventEmitter {
190187 this . $devicesService . on ( DeviceDiscoveryEventNames . DEVICE_LOST , async ( device : Mobile . IDevice ) => {
191188 this . $logger . trace ( `Received ${ DeviceDiscoveryEventNames . DEVICE_LOST } event in LiveSync service for ${ device . deviceInfo . identifier } . Will stop LiveSync operation for this device.` ) ;
192189
193- // for (const projectDir in this.liveSyncProcessesInfo) {
194- // try {
195- // if (_.find(this.liveSyncProcessesInfo[projectDir].deviceDescriptors, d => d.identifier === device.deviceInfo.identifier)) {
196- // await this.stopLiveSync(projectDir, [device.deviceInfo.identifier]);
197- // }
198- // } catch (err) {
199- // this.$logger.warn(`Unable to stop LiveSync operation for ${device.deviceInfo.identifier}.`, err);
200- // }
201- // }
190+ for ( const projectDir in this . $runOnDevicesDataService . getAllData ( ) ) {
191+ try {
192+ const deviceDescriptors = this . $runOnDevicesDataService . getDeviceDescriptors ( projectDir ) ;
193+ if ( _ . find ( deviceDescriptors , d => d . identifier === device . deviceInfo . identifier ) ) {
194+ await this . stopRunOnDevices ( projectDir , [ device . deviceInfo . identifier ] ) ;
195+ }
196+ } catch ( err ) {
197+ this . $logger . warn ( `Unable to stop LiveSync operation for ${ device . deviceInfo . identifier } .` , err ) ;
198+ }
199+ }
202200 } ) ;
203201 }
204202}
0 commit comments