@@ -2,13 +2,11 @@ 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 { LivesyncTool } from "./livesync-library" ;
5
6
import * as path from "path" ;
6
7
7
- const LivesyncTool = require ( "nativescript-android-livesync-lib" ) ;
8
-
9
8
export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBase implements IAndroidNativeScriptDeviceLiveSyncService , INativeScriptDeviceLiveSyncService {
10
- private port : number ;
11
- private livesyncTool : any ;
9
+ private livesyncTool : ILivesyncTool ;
12
10
13
11
constructor (
14
12
private data : IProjectData ,
@@ -19,7 +17,7 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
19
17
protected device : Mobile . IAndroidDevice ,
20
18
private $options : ICommonOptions ) {
21
19
super ( $platformsData , device ) ;
22
- this . livesyncTool = new LivesyncTool ( ) ;
20
+ this . livesyncTool = this . $injector . resolve ( LivesyncTool ) ;
23
21
}
24
22
25
23
public async beforeLiveSyncAction ( deviceAppData : Mobile . IDeviceAppData ) : Promise < void > {
@@ -33,24 +31,24 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
33
31
const canExecuteFastSync = ! liveSyncInfo . isFullSync && ! _ . some ( liveSyncInfo . modifiedFilesData ,
34
32
( localToDevicePath : Mobile . ILocalToDevicePathData ) => ! this . canExecuteFastSync ( localToDevicePath . getLocalPath ( ) , projectData , this . device . deviceInfo . platform ) ) ;
35
33
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 ) ;
39
37
40
38
//TODO clear interval on exit sygnals/stopLivesync
41
39
const syncInterval : NodeJS . Timer = setInterval ( ( ) => {
42
- if ( this . livesyncTool . isOperationInProgress ( operationUid ) ) {
40
+ if ( this . livesyncTool . isOperationInProgress ( operationIdentifier ) ) {
43
41
this . $logger . info ( "Sync operation in progress..." ) ;
44
42
}
45
43
} , 10000 ) ;
46
44
47
45
const clearSyncInterval = ( ) => {
48
46
clearInterval ( syncInterval ) ;
49
- }
47
+ } ;
50
48
doSyncPromise . then ( clearSyncInterval , clearSyncInterval ) ;
51
49
await doSyncPromise ;
52
50
53
- if ( ! canExecuteFastSync ) {
51
+ if ( ! canExecuteFastSync ) {
54
52
await this . device . applicationManager . restartApplication ( { appId : liveSyncInfo . deviceAppData . appIdentifier , projectName : projectData . projectName } ) ;
55
53
}
56
54
}
@@ -59,7 +57,7 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
59
57
}
60
58
61
59
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 ; } ) ) ;
63
61
}
64
62
65
63
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
75
73
}
76
74
77
75
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 ( ) ) ) ;
79
77
80
78
return localToDevicePaths ;
81
79
}
@@ -86,18 +84,18 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
86
84
const currentShasums : IStringDictionary = await deviceHashService . generateHashesFromLocalToDevicePaths ( localToDevicePaths ) ;
87
85
const oldShasums = await deviceHashService . getShasumsFromDevice ( ) ;
88
86
89
- if ( this . $options . force || ! oldShasums ) {
87
+ if ( this . $options . force || ! oldShasums ) {
90
88
await this . livesyncTool . sendDirectory ( projectFilesPath ) ;
91
89
await deviceHashService . uploadHashFileToDevice ( currentShasums ) ;
92
90
transferedFiles = localToDevicePaths ;
93
91
} else {
94
92
const changedShasums = deviceHashService . getChnagedShasums ( oldShasums , currentShasums ) ;
95
93
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 ) ;
98
96
await deviceHashService . uploadHashFileToDevice ( currentShasums ) ;
99
97
transferedFiles = localToDevicePaths . filter ( localToDevicePathData => {
100
- if ( changedFiles . indexOf ( localToDevicePathData . getLocalPath ( ) ) >= 0 ) {
98
+ if ( changedFiles . indexOf ( localToDevicePathData . getLocalPath ( ) ) >= 0 ) {
101
99
return true ;
102
100
}
103
101
} ) ;
@@ -110,13 +108,10 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
110
108
}
111
109
112
110
private async connectLivesyncTool ( projectFilesPath : string , appIdentifier : string ) {
113
- const adbPath = await this . $staticConfig . getAdbFilePath ( ) ;
114
111
await this . livesyncTool . connect ( {
115
- fullApplicationName : appIdentifier ,
116
- port : this . port ,
112
+ appIdentifier,
117
113
deviceIdentifier : this . device . deviceInfo . identifier ,
118
- baseDir : projectFilesPath ,
119
- adbPath : adbPath
114
+ appPlatformsPath : projectFilesPath
120
115
} ) ;
121
116
}
122
117
0 commit comments