@@ -2,8 +2,10 @@ import { DeviceAndroidDebugBridge } from "../../common/mobile/android/device-and
2
2
import { AndroidDeviceHashService } from "../../common/mobile/android/android-device-hash-service" ;
3
3
import { DeviceLiveSyncServiceBase } from "./device-livesync-service-base" ;
4
4
import { APP_FOLDER_NAME } from "../../constants" ;
5
+ import { LiveSyncPaths } from "../../common/constants" ;
5
6
import { AndroidLivesyncTool } from "./android-livesync-tool" ;
6
7
import * as path from "path" ;
8
+ import * as temp from "temp" ;
7
9
8
10
export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBase implements IAndroidNativeScriptDeviceLiveSyncService , INativeScriptDeviceLiveSyncService {
9
11
private livesyncTool : IAndroidLivesyncTool ;
@@ -17,54 +19,65 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
17
19
private $logger : ILogger ,
18
20
protected device : Mobile . IAndroidDevice ,
19
21
private $options : ICommonOptions ,
20
- private $processService : IProcessService ) {
22
+ private $processService : IProcessService ,
23
+ private $fs : IFileSystem ) {
21
24
super ( $platformsData , device ) ;
22
25
this . livesyncTool = this . $injector . resolve ( AndroidLivesyncTool ) ;
23
26
}
24
27
25
28
public async beforeLiveSyncAction ( deviceAppData : Mobile . IDeviceAppData ) : Promise < void > {
26
29
const platformData = this . $platformsData . getPlatformData ( deviceAppData . platform , this . data ) ;
27
30
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 ) ;
28
34
await this . device . applicationManager . startApplication ( { appId : deviceAppData . appIdentifier , projectName : this . data . projectName } ) ;
29
35
await this . connectLivesyncTool ( projectFilesPath , this . data . projectId ) ;
30
36
}
31
37
38
+ private getPathToLiveSyncFileOnDevice ( appIdentifier : string ) : string {
39
+ return `${ LiveSyncPaths . ANDROID_TMP_DIR_NAME } /${ appIdentifier } -livesync-in-progress` ;
40
+ }
41
+
32
42
public async finalizeSync ( liveSyncInfo : ILiveSyncResultInfo ) {
33
43
await this . doSync ( liveSyncInfo ) ;
34
44
}
35
45
36
- private async doSync ( liveSyncInfo : ILiveSyncResultInfo , { doRefresh = false } : { doRefresh ?: boolean } = { } ) : Promise < IAndroidLivesyncSyncOperationResult > {
46
+ private async doSync ( liveSyncInfo : ILiveSyncResultInfo , { doRefresh = false } : { doRefresh ?: boolean } = { } ) : Promise < IAndroidLivesyncSyncOperationResult > {
37
47
const operationId = this . livesyncTool . generateOperationIdentifier ( ) ;
38
48
39
- let result = { operationId, didRefresh : true } ;
49
+ let result = { operationId, didRefresh : true } ;
40
50
41
51
if ( liveSyncInfo . modifiedFilesData . length ) {
42
52
43
53
const doSyncPromise = this . livesyncTool . sendDoSyncOperation ( doRefresh , null , operationId ) ;
44
54
45
- const syncInterval : NodeJS . Timer = setInterval ( ( ) => {
55
+ const syncInterval : NodeJS . Timer = setInterval ( ( ) => {
46
56
if ( this . livesyncTool . isOperationInProgress ( operationId ) ) {
47
57
this . $logger . info ( "Sync operation in progress..." ) ;
48
58
}
49
59
} , AndroidDeviceSocketsLiveSyncService . STATUS_UPDATE_INTERVAL ) ;
50
60
51
- const clearSyncInterval = ( ) => {
61
+ const actionOnEnd = async ( ) => {
52
62
clearInterval ( syncInterval ) ;
63
+ await this . device . fileSystem . deleteFile ( this . getPathToLiveSyncFileOnDevice ( liveSyncInfo . deviceAppData . appIdentifier ) , liveSyncInfo . deviceAppData . appIdentifier ) ;
53
64
} ;
54
65
55
- this . $processService . attachToProcessExitSignals ( this , clearSyncInterval ) ;
56
- doSyncPromise . then ( clearSyncInterval , clearSyncInterval ) ;
66
+ this . $processService . attachToProcessExitSignals ( this , actionOnEnd ) ;
67
+ doSyncPromise . then ( actionOnEnd , actionOnEnd ) ;
57
68
58
69
result = await doSyncPromise ;
59
70
}
60
71
72
+ await this . device . fileSystem . deleteFile ( this . getPathToLiveSyncFileOnDevice ( liveSyncInfo . deviceAppData . appIdentifier ) , liveSyncInfo . deviceAppData . appIdentifier ) ;
73
+
61
74
return result ;
62
75
}
63
76
64
77
public async refreshApplication ( projectData : IProjectData , liveSyncInfo : ILiveSyncResultInfo ) {
65
78
const canExecuteFastSync = ! liveSyncInfo . isFullSync && this . canExecuteFastSyncForPaths ( liveSyncInfo . modifiedFilesData , projectData , this . device . deviceInfo . platform ) ;
66
79
67
- const syncOperationResult = await this . doSync ( liveSyncInfo , { doRefresh : canExecuteFastSync } ) ;
80
+ const syncOperationResult = await this . doSync ( liveSyncInfo , { doRefresh : canExecuteFastSync } ) ;
68
81
69
82
this . livesyncTool . end ( ) ;
70
83
@@ -96,28 +109,28 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
96
109
}
97
110
98
111
private async _transferDirectory ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
99
- let transferredLocalToDevicePaths : Mobile . ILocalToDevicePathData [ ] ;
112
+ let transferredLocalToDevicePaths : Mobile . ILocalToDevicePathData [ ] ;
100
113
const deviceHashService = this . getDeviceHashService ( deviceAppData . appIdentifier ) ;
101
114
const currentShasums : IStringDictionary = await deviceHashService . generateHashesFromLocalToDevicePaths ( localToDevicePaths ) ;
102
115
const oldShasums = await deviceHashService . getShasumsFromDevice ( ) ;
103
116
104
117
if ( this . $options . force || ! oldShasums ) {
105
118
await this . livesyncTool . sendDirectory ( projectFilesPath ) ;
106
119
await deviceHashService . uploadHashFileToDevice ( currentShasums ) ;
107
- transferredLocalToDevicePaths = localToDevicePaths ;
120
+ transferredLocalToDevicePaths = localToDevicePaths ;
108
121
} else {
109
122
const changedShasums = deviceHashService . getChangedShasums ( oldShasums , currentShasums ) ;
110
123
const changedFiles = _ . keys ( changedShasums ) ;
111
124
if ( changedFiles . length ) {
112
125
await this . livesyncTool . sendFiles ( changedFiles ) ;
113
126
await deviceHashService . uploadHashFileToDevice ( currentShasums ) ;
114
- transferredLocalToDevicePaths = localToDevicePaths . filter ( localToDevicePathData => changedFiles . indexOf ( localToDevicePathData . getLocalPath ( ) ) >= 0 ) ;
127
+ transferredLocalToDevicePaths = localToDevicePaths . filter ( localToDevicePathData => changedFiles . indexOf ( localToDevicePathData . getLocalPath ( ) ) >= 0 ) ;
115
128
} else {
116
- transferredLocalToDevicePaths = [ ] ;
129
+ transferredLocalToDevicePaths = [ ] ;
117
130
}
118
131
}
119
132
120
- return transferredLocalToDevicePaths ;
133
+ return transferredLocalToDevicePaths ;
121
134
}
122
135
123
136
private async connectLivesyncTool ( projectFilesPath : string , appIdentifier : string ) {
0 commit comments