@@ -2,13 +2,11 @@ import { DeviceAndroidDebugBridge } from "../../common/mobile/android/device-and
22import { AndroidDeviceHashService } from "../../common/mobile/android/android-device-hash-service" ;
33import { DeviceLiveSyncServiceBase } from "./device-livesync-service-base" ;
44import { APP_FOLDER_NAME } from "../../constants" ;
5+ import { LivesyncTool } from "./livesync-library" ;
56import * as path from "path" ;
67
7- const LivesyncTool = require ( "nativescript-android-livesync-lib" ) ;
8-
98export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBase implements IAndroidNativeScriptDeviceLiveSyncService , INativeScriptDeviceLiveSyncService {
10- private port : number ;
11- private livesyncTool : any ;
9+ private livesyncTool : ILivesyncTool ;
1210
1311 constructor (
1412 private data : IProjectData ,
@@ -19,7 +17,7 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
1917 protected device : Mobile . IAndroidDevice ,
2018 private $options : ICommonOptions ) {
2119 super ( $platformsData , device ) ;
22- this . livesyncTool = new LivesyncTool ( ) ;
20+ this . livesyncTool = this . $injector . resolve ( LivesyncTool ) ;
2321 }
2422
2523 public async beforeLiveSyncAction ( deviceAppData : Mobile . IDeviceAppData ) : Promise < void > {
@@ -33,24 +31,24 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
3331 const canExecuteFastSync = ! liveSyncInfo . isFullSync && ! _ . some ( liveSyncInfo . modifiedFilesData ,
3432 ( localToDevicePath : Mobile . ILocalToDevicePathData ) => ! this . canExecuteFastSync ( localToDevicePath . getLocalPath ( ) , projectData , this . device . deviceInfo . platform ) ) ;
3533
36- if ( liveSyncInfo . modifiedFilesData . length ) {
37- const operationUid = this . livesyncTool . generateOperationUid ( ) ;
38- const doSyncPromise = this . livesyncTool . sendDoSyncOperation ( operationUid ) ;
34+ if ( liveSyncInfo . modifiedFilesData . length ) {
35+ const operationIdentifier = this . livesyncTool . generateOperationIdentifier ( ) ;
36+ const doSyncPromise = this . livesyncTool . sendDoSyncOperation ( operationIdentifier ) ;
3937
4038 //TODO clear interval on exit sygnals/stopLivesync
4139 const syncInterval : NodeJS . Timer = setInterval ( ( ) => {
42- if ( this . livesyncTool . isOperationInProgress ( operationUid ) ) {
40+ if ( this . livesyncTool . isOperationInProgress ( operationIdentifier ) ) {
4341 this . $logger . info ( "Sync operation in progress..." ) ;
4442 }
4543 } , 10000 ) ;
4644
4745 const clearSyncInterval = ( ) => {
4846 clearInterval ( syncInterval ) ;
49- }
47+ } ;
5048 doSyncPromise . then ( clearSyncInterval , clearSyncInterval ) ;
5149 await doSyncPromise ;
5250
53- if ( ! canExecuteFastSync ) {
51+ if ( ! canExecuteFastSync ) {
5452 await this . device . applicationManager . restartApplication ( { appId : liveSyncInfo . deviceAppData . appIdentifier , projectName : projectData . projectName } ) ;
5553 }
5654 }
@@ -59,7 +57,7 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
5957 }
6058
6159 public async removeFiles ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string ) : Promise < void > {
62- await this . livesyncTool . removeFilesArray ( _ . map ( localToDevicePaths , ( element : any ) => { return element . filePath } ) ) ;
60+ await this . livesyncTool . removeFiles ( _ . map ( localToDevicePaths , ( element : any ) => { return element . filePath ; } ) ) ;
6361 }
6462
6563 public async transferFiles ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string , isFullSync : boolean ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
@@ -75,7 +73,7 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
7573 }
7674
7775 private async _transferFiles ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
78- await this . livesyncTool . sendFilesArray ( localToDevicePaths . map ( localToDevicePathData => localToDevicePathData . getLocalPath ( ) ) ) ;
76+ await this . livesyncTool . sendFiles ( localToDevicePaths . map ( localToDevicePathData => localToDevicePathData . getLocalPath ( ) ) ) ;
7977
8078 return localToDevicePaths ;
8179 }
@@ -86,18 +84,18 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
8684 const currentShasums : IStringDictionary = await deviceHashService . generateHashesFromLocalToDevicePaths ( localToDevicePaths ) ;
8785 const oldShasums = await deviceHashService . getShasumsFromDevice ( ) ;
8886
89- if ( this . $options . force || ! oldShasums ) {
87+ if ( this . $options . force || ! oldShasums ) {
9088 await this . livesyncTool . sendDirectory ( projectFilesPath ) ;
9189 await deviceHashService . uploadHashFileToDevice ( currentShasums ) ;
9290 transferedFiles = localToDevicePaths ;
9391 } else {
9492 const changedShasums = deviceHashService . getChnagedShasums ( oldShasums , currentShasums ) ;
9593 const changedFiles = _ . map ( changedShasums , ( hash : string , pathToFile : string ) => pathToFile ) ;
96- if ( changedFiles . length ) {
97- await this . livesyncTool . sendFilesArray ( changedFiles ) ;
94+ if ( changedFiles . length ) {
95+ await this . livesyncTool . sendFiles ( changedFiles ) ;
9896 await deviceHashService . uploadHashFileToDevice ( currentShasums ) ;
9997 transferedFiles = localToDevicePaths . filter ( localToDevicePathData => {
100- if ( changedFiles . indexOf ( localToDevicePathData . getLocalPath ( ) ) >= 0 ) {
98+ if ( changedFiles . indexOf ( localToDevicePathData . getLocalPath ( ) ) >= 0 ) {
10199 return true ;
102100 }
103101 } ) ;
@@ -110,13 +108,10 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
110108 }
111109
112110 private async connectLivesyncTool ( projectFilesPath : string , appIdentifier : string ) {
113- const adbPath = await this . $staticConfig . getAdbFilePath ( ) ;
114111 await this . livesyncTool . connect ( {
115- fullApplicationName : appIdentifier ,
116- port : this . port ,
112+ appIdentifier,
117113 deviceIdentifier : this . device . deviceInfo . identifier ,
118- baseDir : projectFilesPath ,
119- adbPath : adbPath
114+ appPlatformsPath : projectFilesPath
120115 } ) ;
121116 }
122117
0 commit comments