Skip to content

Commit d9f8cb8

Browse files
committed
Await sync before restart. Update checksums.
1 parent 27babb8 commit d9f8cb8

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

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

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,22 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
2424
public async beforeLiveSyncAction(deviceAppData: Mobile.IDeviceAppData): Promise<void> {
2525
const platformData = this.$platformsData.getPlatformData(deviceAppData.platform, this.data);
2626
const projectFilesPath = path.join(platformData.appDestinationDirectoryPath, APP_FOLDER_NAME);
27-
await this.connectLivesyncTool(projectFilesPath, this.data.projectId);
2827
await this.device.applicationManager.startApplication({ appId: deviceAppData.appIdentifier, projectName: this.data.projectName });
28+
await this.connectLivesyncTool(projectFilesPath, this.data.projectId);
2929
}
3030

3131
public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void> {
32-
await this.livesyncTool.sendDoSyncOperation()
32+
const canExecuteFastSync = !liveSyncInfo.isFullSync && !_.some(liveSyncInfo.modifiedFilesData,
33+
(localToDevicePath: Mobile.ILocalToDevicePathData) => !this.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, this.device.deviceInfo.platform));
34+
35+
if(!canExecuteFastSync && liveSyncInfo.modifiedFilesData.length) {
36+
await this.livesyncTool.sendDoSyncOperation();
37+
await this.device.applicationManager.restartApplication({ appId: liveSyncInfo.deviceAppData.appIdentifier, projectName: projectData.projectName });
38+
} else if(liveSyncInfo.modifiedFilesData.length) {
39+
await this.livesyncTool.sendDoSyncOperation();
40+
}
41+
42+
this.livesyncTool.end();
3343
}
3444

3545
public async removeFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<void> {
@@ -42,7 +52,7 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
4252
if (isFullSync) {
4353
transferredFiles = await this._transferDirectory(deviceAppData, localToDevicePaths, projectFilesPath);
4454
} else {
45-
transferredFiles = this._transferFiles(deviceAppData, localToDevicePaths, projectFilesPath);
55+
transferredFiles = await this._transferFiles(deviceAppData, localToDevicePaths, projectFilesPath);
4656
}
4757

4858
return transferredFiles;
@@ -55,19 +65,32 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
5565
}
5666

5767
private async _transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<Mobile.ILocalToDevicePathData[]> {
68+
let transferedFiles: Mobile.ILocalToDevicePathData[];
5869
const deviceHashService = this.getDeviceHashService(deviceAppData.appIdentifier);
5970
const currentShasums: IStringDictionary = await deviceHashService.generateHashesFromLocalToDevicePaths(localToDevicePaths);
6071
const oldShasums = await deviceHashService.getShasumsFromDevice();
6172

6273
if(this.$options.force || !oldShasums) {
63-
this.livesyncTool.sendDirectory(projectFilesPath);
64-
65-
return localToDevicePaths;
74+
await this.livesyncTool.sendDirectory(projectFilesPath);
75+
await deviceHashService.uploadHashFileToDevice(currentShasums);
76+
transferedFiles = localToDevicePaths;
6677
} else {
6778
const changedShasums = deviceHashService.getChnagedShasums(oldShasums, currentShasums);
68-
await this.livesyncTool.sendFilesArray(_.map(changedShasums, (hash: string, pathToFile: string) => pathToFile));
69-
await deviceHashService.uploadHashFileToDevice(currentShasums);
79+
const changedFiles = _.map(changedShasums, (hash: string, pathToFile: string) => pathToFile);
80+
if(changedFiles.length){
81+
await this.livesyncTool.sendFilesArray(changedFiles);
82+
await deviceHashService.uploadHashFileToDevice(currentShasums);
83+
transferedFiles = localToDevicePaths.filter(localToDevicePathData => {
84+
if(changedFiles.indexOf(localToDevicePathData.getLocalPath()) >= 0){
85+
return true;
86+
}
87+
});
88+
} else {
89+
transferedFiles = [];
90+
}
7091
}
92+
93+
return transferedFiles;
7194
}
7295

7396
private async connectLivesyncTool(projectFilesPath: string, appIdentifier: string) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as path from "path";
22
import * as util from "util";
33
import { APP_FOLDER_NAME } from "../../constants";
4-
import { getHash } from "../common/helpers";
4+
import { getHash } from "../../common/helpers";
55

66
export abstract class PlatformLiveSyncServiceBase {
77
private _deviceLiveSyncServicesCache: IDictionary<INativeScriptDeviceLiveSyncService> = {};
@@ -58,9 +58,14 @@ export abstract class PlatformLiveSyncServiceBase {
5858

5959
public async liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo> {
6060
const projectData = liveSyncInfo.projectData;
61+
const deviceLiveSyncService = this.getDeviceLiveSyncService(device, projectData);
6162
const syncInfo = _.merge<IFullSyncInfo>({ device, watch: true }, liveSyncInfo);
6263
const deviceAppData = await this.getAppData(syncInfo);
6364

65+
if (deviceLiveSyncService.beforeLiveSyncAction) {
66+
await deviceLiveSyncService.beforeLiveSyncAction(deviceAppData);
67+
}
68+
6469
let modifiedLocalToDevicePaths: Mobile.ILocalToDevicePathData[] = [];
6570
if (liveSyncInfo.filesToSync.length) {
6671
const filesToSync = liveSyncInfo.filesToSync;

0 commit comments

Comments
 (0)