Skip to content

Commit ccf2a4d

Browse files
committed
fix: debug doesn't await file trasfer end with socket implementation
1 parent 038a981 commit ccf2a4d

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

lib/definitions/livesync.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ interface IPlatformLiveSyncService {
338338
liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo>;
339339
refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void>;
340340
prepareForLiveSync(device: Mobile.IDevice, data: IProjectDir, liveSyncInfo: ILiveSyncInfo): Promise<void>;
341+
getDeviceLiveSyncService(device: Mobile.IDevice, projectData: IProjectData): INativeScriptDeviceLiveSyncService;
341342
}
342343

343344
interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase {
@@ -370,6 +371,13 @@ interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase
370371
* @return {Promise<Mobile.ILocalToDevicePathData[]>} Returns the ILocalToDevicePathData of all transfered files
371372
*/
372373
transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, isFullSync: boolean): Promise<Mobile.ILocalToDevicePathData[]>;
374+
375+
/**
376+
* Guarantees all remove/update operations have finished
377+
* @param {ILiveSyncResultInfo} liveSyncInfo Describes the LiveSync operation - for which project directory is the operation and other settings.
378+
* @return {Promise<void>}
379+
*/
380+
finalizeSync(liveSyncInfo: ILiveSyncResultInfo): Promise<void>;
373381
}
374382

375383
interface IAndroidNativeScriptDeviceLiveSyncService {

lib/services/livesync/android-device-livesync-sockets-service.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,22 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
2929
await this.connectLivesyncTool(projectFilesPath, this.data.projectId);
3030
}
3131

32-
public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void> {
33-
const canExecuteFastSync = !liveSyncInfo.isFullSync && this.canExecuteFastSyncForPaths(liveSyncInfo.modifiedFilesData, projectData, this.device.deviceInfo.platform);
32+
public async finalizeSync(liveSyncInfo: ILiveSyncResultInfo) {
33+
await this.doSync(liveSyncInfo, false);
34+
}
35+
36+
private async doSync(liveSyncInfo: ILiveSyncResultInfo, doRefresh = false): Promise<IAndroidLivesyncSyncOperationResult> {
37+
let result;
38+
const operationId = this.livesyncTool.generateOperationIdentifier();
39+
40+
result = {operationId, didRefresh: true };
3441

3542
if (liveSyncInfo.modifiedFilesData.length) {
36-
const operationIdentifier = this.livesyncTool.generateOperationIdentifier();
3743

38-
const doSyncPromise = this.livesyncTool.sendDoSyncOperation(canExecuteFastSync, null, operationIdentifier);
44+
const doSyncPromise = this.livesyncTool.sendDoSyncOperation(doRefresh, null, operationId);
3945

4046
const syncInterval : NodeJS.Timer = setInterval(() => {
41-
if (this.livesyncTool.isOperationInProgress(operationIdentifier)) {
47+
if (this.livesyncTool.isOperationInProgress(operationId)) {
4248
this.$logger.info("Sync operation in progress...");
4349
}
4450
}, AndroidDeviceSocketsLiveSyncService.STATUS_UPDATE_INTERVAL);
@@ -50,14 +56,22 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
5056
this.$processService.attachToProcessExitSignals(this, clearSyncInterval);
5157
doSyncPromise.then(clearSyncInterval, clearSyncInterval);
5258

53-
const refreshResult = await doSyncPromise;
54-
55-
if (!canExecuteFastSync || !refreshResult.didRefresh) {
56-
await this.device.applicationManager.restartApplication({ appId: liveSyncInfo.deviceAppData.appIdentifier, projectName: projectData.projectName });
57-
}
59+
result = await doSyncPromise;
5860
}
5961

62+
return result;
63+
}
64+
65+
public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo) {
66+
const canExecuteFastSync = !liveSyncInfo.isFullSync && this.canExecuteFastSyncForPaths(liveSyncInfo.modifiedFilesData, projectData, this.device.deviceInfo.platform);
67+
68+
const syncOperationResult = await this.doSync(liveSyncInfo, canExecuteFastSync);
69+
6070
this.livesyncTool.end();
71+
72+
if (!canExecuteFastSync || !syncOperationResult.didRefresh) {
73+
await this.device.applicationManager.restartApplication({ appId: liveSyncInfo.deviceAppData.appIdentifier, projectName: projectData.projectName });
74+
}
6175
}
6276

6377
public async removeFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<void> {

lib/services/livesync/device-livesync-service-base.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ export abstract class DeviceLiveSyncServiceBase {
3838

3939
return transferredFiles;
4040
}
41+
42+
public async finalizeSync(liveSyncInfo: ILiveSyncResultInfo): Promise<void> {
43+
//implement in case a sync point for all remove/create operation is needed
44+
}
4145
}

lib/services/livesync/livesync-service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
164164
};
165165

166166
try {
167+
const platformLiveSyncService = this.getLiveSyncService(liveSyncResultInfo.deviceAppData.platform);
168+
const deviceLivesyncService = platformLiveSyncService.getDeviceLiveSyncService(deviceAppData.device, projectData);
169+
await deviceLivesyncService.finalizeSync(liveSyncResultInfo);
167170
await deviceAppData.device.applicationManager.stopApplication({ appId: applicationId, projectName: projectData.projectName });
168171
// Now that we've stopped the application we know it isn't started, so set debugOptions.start to false
169172
// so that it doesn't default to true in attachDebugger method

0 commit comments

Comments
 (0)