@@ -2,8 +2,10 @@ 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 { LiveSyncPaths } from "../../common/constants" ;
56import { AndroidLivesyncTool } from "./android-livesync-tool" ;
67import * as path from "path" ;
8+ import * as temp from "temp" ;
79
810export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBase implements IAndroidNativeScriptDeviceLiveSyncService , INativeScriptDeviceLiveSyncService {
911 private livesyncTool : IAndroidLivesyncTool ;
@@ -17,54 +19,65 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
1719 private $logger : ILogger ,
1820 protected device : Mobile . IAndroidDevice ,
1921 private $options : ICommonOptions ,
20- private $processService : IProcessService ) {
22+ private $processService : IProcessService ,
23+ private $fs : IFileSystem ) {
2124 super ( $platformsData , device ) ;
2225 this . livesyncTool = this . $injector . resolve ( AndroidLivesyncTool ) ;
2326 }
2427
2528 public async beforeLiveSyncAction ( deviceAppData : Mobile . IDeviceAppData ) : Promise < void > {
2629 const platformData = this . $platformsData . getPlatformData ( deviceAppData . platform , this . data ) ;
2730 const projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , APP_FOLDER_NAME ) ;
31+ const pathToLiveSyncFile = temp . path ( { prefix : "livesync" } ) ;
32+ this . $fs . writeFile ( pathToLiveSyncFile , "" ) ;
33+ await this . device . fileSystem . putFile ( pathToLiveSyncFile , this . getPathToLiveSyncFileOnDevice ( deviceAppData . appIdentifier ) , deviceAppData . appIdentifier ) ;
2834 await this . device . applicationManager . startApplication ( { appId : deviceAppData . appIdentifier , projectName : this . data . projectName } ) ;
2935 await this . connectLivesyncTool ( projectFilesPath , this . data . projectId ) ;
3036 }
3137
38+ private getPathToLiveSyncFileOnDevice ( appIdentifier : string ) : string {
39+ return `${ LiveSyncPaths . ANDROID_TMP_DIR_NAME } /${ appIdentifier } -livesync-in-progress` ;
40+ }
41+
3242 public async finalizeSync ( liveSyncInfo : ILiveSyncResultInfo ) {
3343 await this . doSync ( liveSyncInfo ) ;
3444 }
3545
36- private async doSync ( liveSyncInfo : ILiveSyncResultInfo , { doRefresh = false } : { doRefresh ?: boolean } = { } ) : Promise < IAndroidLivesyncSyncOperationResult > {
46+ private async doSync ( liveSyncInfo : ILiveSyncResultInfo , { doRefresh = false } : { doRefresh ?: boolean } = { } ) : Promise < IAndroidLivesyncSyncOperationResult > {
3747 const operationId = this . livesyncTool . generateOperationIdentifier ( ) ;
3848
39- let result = { operationId, didRefresh : true } ;
49+ let result = { operationId, didRefresh : true } ;
4050
4151 if ( liveSyncInfo . modifiedFilesData . length ) {
4252
4353 const doSyncPromise = this . livesyncTool . sendDoSyncOperation ( doRefresh , null , operationId ) ;
4454
45- const syncInterval : NodeJS . Timer = setInterval ( ( ) => {
55+ const syncInterval : NodeJS . Timer = setInterval ( ( ) => {
4656 if ( this . livesyncTool . isOperationInProgress ( operationId ) ) {
4757 this . $logger . info ( "Sync operation in progress..." ) ;
4858 }
4959 } , AndroidDeviceSocketsLiveSyncService . STATUS_UPDATE_INTERVAL ) ;
5060
51- const clearSyncInterval = ( ) => {
61+ const actionOnEnd = async ( ) => {
5262 clearInterval ( syncInterval ) ;
63+ await this . device . fileSystem . deleteFile ( this . getPathToLiveSyncFileOnDevice ( liveSyncInfo . deviceAppData . appIdentifier ) , liveSyncInfo . deviceAppData . appIdentifier ) ;
5364 } ;
5465
55- this . $processService . attachToProcessExitSignals ( this , clearSyncInterval ) ;
56- doSyncPromise . then ( clearSyncInterval , clearSyncInterval ) ;
66+ this . $processService . attachToProcessExitSignals ( this , actionOnEnd ) ;
67+ doSyncPromise . then ( actionOnEnd , actionOnEnd ) ;
5768
5869 result = await doSyncPromise ;
5970 }
6071
72+ await this . device . fileSystem . deleteFile ( this . getPathToLiveSyncFileOnDevice ( liveSyncInfo . deviceAppData . appIdentifier ) , liveSyncInfo . deviceAppData . appIdentifier ) ;
73+
6174 return result ;
6275 }
6376
6477 public async refreshApplication ( projectData : IProjectData , liveSyncInfo : ILiveSyncResultInfo ) {
6578 const canExecuteFastSync = ! liveSyncInfo . isFullSync && this . canExecuteFastSyncForPaths ( liveSyncInfo . modifiedFilesData , projectData , this . device . deviceInfo . platform ) ;
6679
67- const syncOperationResult = await this . doSync ( liveSyncInfo , { doRefresh : canExecuteFastSync } ) ;
80+ const syncOperationResult = await this . doSync ( liveSyncInfo , { doRefresh : canExecuteFastSync } ) ;
6881
6982 this . livesyncTool . end ( ) ;
7083
@@ -96,28 +109,28 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
96109 }
97110
98111 private async _transferDirectory ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
99- let transferredLocalToDevicePaths : Mobile . ILocalToDevicePathData [ ] ;
112+ let transferredLocalToDevicePaths : Mobile . ILocalToDevicePathData [ ] ;
100113 const deviceHashService = this . getDeviceHashService ( deviceAppData . appIdentifier ) ;
101114 const currentShasums : IStringDictionary = await deviceHashService . generateHashesFromLocalToDevicePaths ( localToDevicePaths ) ;
102115 const oldShasums = await deviceHashService . getShasumsFromDevice ( ) ;
103116
104117 if ( this . $options . force || ! oldShasums ) {
105118 await this . livesyncTool . sendDirectory ( projectFilesPath ) ;
106119 await deviceHashService . uploadHashFileToDevice ( currentShasums ) ;
107- transferredLocalToDevicePaths = localToDevicePaths ;
120+ transferredLocalToDevicePaths = localToDevicePaths ;
108121 } else {
109122 const changedShasums = deviceHashService . getChangedShasums ( oldShasums , currentShasums ) ;
110123 const changedFiles = _ . keys ( changedShasums ) ;
111124 if ( changedFiles . length ) {
112125 await this . livesyncTool . sendFiles ( changedFiles ) ;
113126 await deviceHashService . uploadHashFileToDevice ( currentShasums ) ;
114- transferredLocalToDevicePaths = localToDevicePaths . filter ( localToDevicePathData => changedFiles . indexOf ( localToDevicePathData . getLocalPath ( ) ) >= 0 ) ;
127+ transferredLocalToDevicePaths = localToDevicePaths . filter ( localToDevicePathData => changedFiles . indexOf ( localToDevicePathData . getLocalPath ( ) ) >= 0 ) ;
115128 } else {
116- transferredLocalToDevicePaths = [ ] ;
129+ transferredLocalToDevicePaths = [ ] ;
117130 }
118131 }
119132
120- return transferredLocalToDevicePaths ;
133+ return transferredLocalToDevicePaths ;
121134 }
122135
123136 private async connectLivesyncTool ( projectFilesPath : string , appIdentifier : string ) {
0 commit comments