Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/common
1 change: 1 addition & 0 deletions lib/definitions/livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface ILiveSyncProcessInfo {
isStopped: boolean;
deviceDescriptors: ILiveSyncDeviceInfo[];
currentSyncAction: Promise<any>;
syncToPreviewApp: boolean;
}

interface IOptionalOutputPath {
Expand Down
16 changes: 8 additions & 8 deletions lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi

liveSyncProcessInfo.deviceDescriptors = [];

if (liveSyncProcessInfo.syncToPreviewApp) {
await this.$previewAppLiveSyncService.stopLiveSync();
}

// Kill typescript watcher
const projectData = this.$projectDataService.getProjectData(projectDir);
await this.$hooksService.executeAfterHooks('watch', {
Expand Down Expand Up @@ -350,6 +354,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
this.liveSyncProcessesInfo[projectDir].actionsChain = this.liveSyncProcessesInfo[projectDir].actionsChain || Promise.resolve();
this.liveSyncProcessesInfo[projectDir].currentSyncAction = this.liveSyncProcessesInfo[projectDir].actionsChain;
this.liveSyncProcessesInfo[projectDir].isStopped = false;
this.liveSyncProcessesInfo[projectDir].syncToPreviewApp = liveSyncData.syncToPreviewApp;

const currentDeviceDescriptors = this.getLiveSyncDeviceDescriptors(projectDir);
this.liveSyncProcessesInfo[projectDir].deviceDescriptors = _.uniqBy(currentDeviceDescriptors.concat(deviceDescriptors), deviceDescriptorPrimaryKey);
Expand Down Expand Up @@ -744,13 +749,6 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
this.liveSyncProcessesInfo[liveSyncData.projectDir].timer = timeoutTimer;

this.$processService.attachToProcessExitSignals(this, () => {
if (liveSyncData.syncToPreviewApp) {
// Do not await here, we are in process exit's handler.
/* tslint:disable:no-floating-promises */
this.$previewAppLiveSyncService.stopLiveSync();
/* tslint:enable:no-floating-promises */
}

_.keys(this.liveSyncProcessesInfo).forEach(projectDir => {
// Do not await here, we are in process exit's handler.
/* tslint:disable:no-floating-promises */
Expand All @@ -768,7 +766,9 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi

for (const projectDir in this.liveSyncProcessesInfo) {
try {
await this.stopLiveSync(projectDir, [device.deviceInfo.identifier]);
if (_.find(this.liveSyncProcessesInfo[projectDir].deviceDescriptors, d => d.identifier === device.deviceInfo.identifier)) {
await this.stopLiveSync(projectDir, [device.deviceInfo.identifier]);
}
} catch (err) {
this.$logger.warn(`Unable to stop LiveSync operation for ${device.deviceInfo.identifier}.`, err);
}
Expand Down
3 changes: 2 additions & 1 deletion test/services/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ describe("liveSyncService", () => {
},
patterns: ["pattern"]
},
deviceDescriptors: []
deviceDescriptors: [],
syncToPreviewApp: false
});

const getDeviceDescriptor = (identifier: string): ILiveSyncDeviceInfo => ({
Expand Down