Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 665ade9

Browse files
FatmeFatme
Fatme
authored and
Fatme
committed
Merge pull request #411 from telerik/fatme/android-livesync
Integrate livesync logic from android runtime
2 parents b88415a + b40833f commit 665ade9

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

declarations.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,11 @@ interface IHtmlHelpService {
264264

265265
interface IUsbLiveSyncServiceBase {
266266
initialize(platform: string): IFuture<string>;
267-
sync(platform: string, appIdentifier: string, localProjectRootPath: string, projectFilesPath: string, excludedProjectDirsAndFiles: string[], watchGlob: any,
267+
sync(platform: string, appIdentifier: string, projectFilesPath: string, excludedProjectDirsAndFiles: string[], watchGlob: any,
268268
restartAppOnDeviceAction: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData) => IFuture<void>,
269269
notInstalledAppOnDeviceAction: (device: Mobile.IDevice) => IFuture<void>,
270-
beforeBatchLiveSyncAction?: (filePath: string) => IFuture<string>,
271-
canLiveSyncAction?: (device: Mobile.IDevice, appIdentifier: string) => IFuture<boolean>): IFuture<void>;
270+
beforeLiveSyncAction?: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData) => IFuture<void>,
271+
beforeBatchLiveSyncAction?: (filePath: string) => IFuture<string>): IFuture<void>;
272272
}
273273

274274
interface ISysInfoData {

services/usb-livesync-service-base.ts

+17-16
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
3434
}).future<string>()();
3535
}
3636

37-
public sync(platform: string, appIdentifier: string, localProjectRootPath: string, projectFilesPath: string, excludedProjectDirsAndFiles: string[], watchGlob: any,
37+
public sync(platform: string, appIdentifier: string, projectFilesPath: string, excludedProjectDirsAndFiles: string[], watchGlob: any,
3838
restartAppOnDeviceAction: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]) => IFuture<void>,
3939
notInstalledAppOnDeviceAction: (device: Mobile.IDevice) => IFuture<void>,
40-
beforeBatchLiveSyncAction?: (filePath: string) => IFuture<string>,
41-
canLiveSyncAction?: (device: Mobile.IDevice, appIdentifier: string) => IFuture<boolean>): IFuture<void> {
40+
beforeLiveSyncAction?: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData) => IFuture<void>,
41+
beforeBatchLiveSyncAction?: (filePath: string) => IFuture<string>): IFuture<void> {
4242
return (() => {
4343
if(!this._initialized) {
4444
this.initialize(platform).wait();
4545
}
4646

4747
let projectFiles = this.$fs.enumerateFilesInDirectorySync(projectFilesPath, (filePath, stat) => !this.isFileExcluded(path.relative(projectFilesPath, filePath), excludedProjectDirsAndFiles, projectFilesPath), { enumerateDirectories: true});
48-
this.syncCore(projectFiles, appIdentifier, localProjectRootPath, restartAppOnDeviceAction, notInstalledAppOnDeviceAction, canLiveSyncAction).wait();
48+
this.syncCore(projectFiles, appIdentifier, projectFilesPath, restartAppOnDeviceAction, notInstalledAppOnDeviceAction).wait();
4949

5050
if(this.$options.watch) {
5151
let __this = this;
@@ -54,7 +54,7 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
5454
this.on('all', (event: string, filePath: string) => {
5555
if(event === "added" || event === "changed") {
5656
if(!_.contains(excludedProjectDirsAndFiles, filePath)) {
57-
__this.batchLiveSync(filePath, appIdentifier, localProjectRootPath, restartAppOnDeviceAction, notInstalledAppOnDeviceAction, beforeBatchLiveSyncAction);
57+
__this.batchLiveSync(filePath, appIdentifier, projectFilesPath, restartAppOnDeviceAction, notInstalledAppOnDeviceAction, beforeLiveSyncAction, beforeBatchLiveSyncAction);
5858
}
5959
}
6060
});
@@ -65,32 +65,33 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
6565
}).future<void>()();
6666
}
6767

68-
private syncCore(projectFiles: string[], appIdentifier: string, localProjectRootPath: string,
68+
private syncCore(projectFiles: string[], appIdentifier: string, projectFilesPath: string,
6969
restartAppOnDeviceAction: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]) => IFuture<void>,
7070
notInstalledAppOnDeviceAction: (device: Mobile.IDevice) => IFuture<void>,
71-
canLiveSyncAction: (device: Mobile.IDevice, appIdentifier: string) => IFuture<boolean>): IFuture<void> {
71+
beforeLiveSyncAction?: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData) => IFuture<void>): IFuture<void> {
7272
return (() => {
7373
let deviceAppData = this.$deviceAppDataFactory.create(appIdentifier, this.$devicesServices.platform);
7474
let localToDevicePaths = _(projectFiles)
7575
.map(projectFile => this.getProjectFileInfo(projectFile))
7676
.filter(projectFileInfo => projectFileInfo.shouldIncludeFile)
77-
.map(projectFileInfo => this.$localToDevicePathDataFactory.create(projectFileInfo.fileName, localProjectRootPath, projectFileInfo.onDeviceName, deviceAppData.deviceProjectRootPath))
77+
.map(projectFileInfo => this.$localToDevicePathDataFactory.create(projectFileInfo.fileName, projectFilesPath, projectFileInfo.onDeviceName, deviceAppData.deviceProjectRootPath))
7878
.value();
7979

8080
let action = (device: Mobile.IDevice) => {
8181
return (() => {
8282
if(deviceAppData.isLiveSyncSupported(device).wait()) {
83+
84+
if(beforeLiveSyncAction) {
85+
beforeLiveSyncAction(device, deviceAppData).wait();
86+
}
87+
8388
let applications = device.applicationManager.getInstalledApplications().wait();
8489
if(!_.contains(applications, deviceAppData.appIdentifier)) {
8590
this.$logger.warn(`The application with id "${deviceAppData.appIdentifier}" is not installed on the device yet.`);
8691
notInstalledAppOnDeviceAction(device).wait();
8792
return;
8893
}
8994

90-
if(canLiveSyncAction && !canLiveSyncAction(device, appIdentifier).wait()) {
91-
return;
92-
}
93-
9495
this.$logger.info("Transfering project files...");
9596
device.fileSystem.transferFiles(deviceAppData.appIdentifier, localToDevicePaths).wait();
9697
this.$logger.info("Successfully transfered all project files.");
@@ -108,11 +109,11 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
108109

109110
private timer: any= null;
110111
private syncQueue: string[] = [];
111-
private batchLiveSync(filePath: string, appIdentifier: string, localProjectRootPath: string,
112+
private batchLiveSync(filePath: string, appIdentifier: string, projectFilesPath: string,
112113
restartAppOnDeviceAction: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]) => IFuture<void>,
113114
notInstalledAppOnDeviceAction: (device: Mobile.IDevice) => IFuture<void>,
114-
beforeBatchLiveSyncAction?: (filePath: string) => IFuture<string>,
115-
canLiveSyncAction?: (device: Mobile.IDevice, appIdentifier: string) => IFuture<boolean>) : void {
115+
beforeLiveSyncAction?: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData) => IFuture<void>,
116+
beforeBatchLiveSyncAction?: (filePath: string) => IFuture<string>) : void {
116117
if(!this.timer) {
117118
this.timer = setInterval(() => {
118119
let filesToSync = this.syncQueue;
@@ -121,7 +122,7 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
121122
this.$logger.trace("Syncing %s", filesToSync.join(", "));
122123
this.$dispatcher.dispatch( () => {
123124
return (() => {
124-
this.syncCore(filesToSync, appIdentifier, localProjectRootPath, restartAppOnDeviceAction, notInstalledAppOnDeviceAction, canLiveSyncAction).wait();
125+
this.syncCore(filesToSync, appIdentifier, projectFilesPath, restartAppOnDeviceAction, notInstalledAppOnDeviceAction, beforeLiveSyncAction).wait();
125126
}).future<void>()();
126127
});
127128
}

0 commit comments

Comments
 (0)