Skip to content

Commit f2caa9d

Browse files
committed
chore: emit runOnDeviceStopperEvent
1 parent 64427e9 commit f2caa9d

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

lib/bootstrap.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,13 @@ $injector.require("platformWatcherService", "./services/platform/platform-watche
4343

4444
$injector.require("buildArtefactsService", "./services/build-artefacts-service");
4545

46-
$injector.require("runOnDevicesDataService", "./services/run-on-devices-data-service");
47-
$injector.require("runOnDevicesEmitter", "./run-on-devices-emitter");
48-
46+
$injector.require("deviceDebugAppService", "./services/device/device-debug-app-service");
4947
$injector.require("deviceInstallAppService", "./services/device/device-install-app-service");
5048
$injector.require("deviceRefreshAppService", "./services/device/device-refresh-app-service");
51-
$injector.require("deviceDebugAppService", "./services/device/device-debug-app-service");
5249

5350
$injector.require("workflowDataService", "./services/workflow/workflow-data-service");
51+
$injector.require("runOnDevicesDataService", "./services/run-on-devices-data-service");
52+
$injector.require("runOnDevicesEmitter", "./run-on-devices-emitter");
5453

5554
$injector.require("mainController", "./controllers/main-controller");
5655
$injector.require("runOnDevicesController", "./controllers/run-on-devices-controller");

lib/controllers/main-controller.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { RunOnDevicesController } from "./run-on-devices-controller";
99
import { RunOnDevicesDataService } from "../services/run-on-devices-data-service";
1010
import { cache } from "../common/decorators";
1111
import { DeviceDiscoveryEventNames } from "../common/constants";
12+
import { RunOnDevicesEmitter } from "../run-on-devices-emitter";
1213

1314
export 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
}

lib/run-on-devices-emitter.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ export class RunOnDevicesEmitter extends EventEmitter {
4242
});
4343
}
4444

45+
public emitRunOnDeviceStoppedEvent(projectDir: string, deviceIdentifier: string) {
46+
this.emitCore(RunOnDeviceEvents.runOnDeviceStopped, {
47+
projectDir,
48+
deviceIdentifier
49+
});
50+
}
51+
4552
public emitDebuggerAttachedEvent(debugInformation: IDebugInformation) {
4653
this.emit(DEBUGGER_ATTACHED_EVENT_NAME, debugInformation);
4754
}

lib/services/run-on-devices-data-service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ export class RunOnDevicesDataService {
55
return this.liveSyncProcessesInfo[projectDir];
66
}
77

8+
public getAllData(): IDictionary<ILiveSyncProcessInfo> {
9+
return this.liveSyncProcessesInfo;
10+
}
11+
812
public getDeviceDescriptors(projectDir: string): ILiveSyncDeviceInfo[] {
913
const liveSyncProcessesInfo = this.liveSyncProcessesInfo[projectDir] || <ILiveSyncProcessInfo>{};
1014
const currentDescriptors = liveSyncProcessesInfo.deviceDescriptors;

0 commit comments

Comments
 (0)