1
1
import { DeviceAndroidDebugBridge } from "../../common/mobile/android/device-android-debug-bridge" ;
2
2
import { AndroidDeviceHashService } from "../../common/mobile/android/android-device-hash-service" ;
3
3
import { DeviceLiveSyncServiceBase } from "./device-livesync-service-base" ;
4
- import { cache } from "../../common/decorators" ;
4
+ import { APP_FOLDER_NAME } from "../../constants" ;
5
+ import * as path from "path" ;
6
+
5
7
const LivesyncTool = require ( "nativescript-android-livesync-lib" ) ;
6
8
7
9
export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBase implements IAndroidNativeScriptDeviceLiveSyncService , INativeScriptDeviceLiveSyncService {
@@ -13,32 +15,61 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
13
15
private $injector : IInjector ,
14
16
protected $platformsData : IPlatformsData ,
15
17
protected $staticConfig : Config . IStaticConfig ,
16
- protected device : Mobile . IAndroidDevice ) {
18
+ protected device : Mobile . IAndroidDevice ,
19
+ private $options : ICommonOptions ) {
17
20
super ( $platformsData , device ) ;
18
21
this . livesyncTool = new LivesyncTool ( ) ;
19
22
}
20
23
21
24
public async beforeLiveSyncAction ( deviceAppData : Mobile . IDeviceAppData ) : Promise < void > {
25
+ const platformData = this . $platformsData . getPlatformData ( deviceAppData . platform , this . data ) ;
26
+ const projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , APP_FOLDER_NAME ) ;
27
+ await this . connectLivesyncTool ( projectFilesPath , this . data . projectId ) ;
22
28
await this . device . applicationManager . startApplication ( { appId : deviceAppData . appIdentifier , projectName : this . data . projectName } ) ;
23
29
}
24
30
25
31
public async refreshApplication ( projectData : IProjectData , liveSyncInfo : ILiveSyncResultInfo ) : Promise < void > {
26
- //await this.connectLivesyncTool("", projectData.projectId);
27
32
await this . livesyncTool . sendDoSyncOperation ( )
28
33
}
29
34
30
35
public async removeFiles ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string ) : Promise < void > {
31
- await this . connectLivesyncTool ( projectFilesPath , deviceAppData . appIdentifier ) ;
32
36
await this . livesyncTool . removeFilesArray ( _ . map ( localToDevicePaths , ( element : any ) => { return element . filePath } ) ) ;
33
37
}
34
38
35
39
public async transferFiles ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string , isFullSync : boolean ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
36
- await this . connectLivesyncTool ( projectFilesPath , deviceAppData . appIdentifier ) ;
40
+ let transferredFiles ;
41
+
42
+ if ( isFullSync ) {
43
+ transferredFiles = await this . _transferDirectory ( deviceAppData , localToDevicePaths , projectFilesPath ) ;
44
+ } else {
45
+ transferredFiles = this . _transferFiles ( deviceAppData , localToDevicePaths , projectFilesPath ) ;
46
+ }
47
+
48
+ return transferredFiles ;
49
+ }
50
+
51
+ private async _transferFiles ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
37
52
await this . livesyncTool . sendFilesArray ( localToDevicePaths . map ( localToDevicePathData => localToDevicePathData . getLocalPath ( ) ) ) ;
38
53
39
54
return localToDevicePaths ;
40
55
}
41
56
57
+ private async _transferDirectory ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
58
+ const deviceHashService = this . getDeviceHashService ( deviceAppData . appIdentifier ) ;
59
+ const currentShasums : IStringDictionary = await deviceHashService . generateHashesFromLocalToDevicePaths ( localToDevicePaths ) ;
60
+ const oldShasums = await deviceHashService . getShasumsFromDevice ( ) ;
61
+
62
+ if ( this . $options . force || ! oldShasums ) {
63
+ this . livesyncTool . sendDirectory ( projectFilesPath ) ;
64
+
65
+ return localToDevicePaths ;
66
+ } else {
67
+ const changedShasums = deviceHashService . getChnagedShasums ( oldShasums , currentShasums ) ;
68
+ await this . livesyncTool . sendFilesArray ( _ . map ( changedShasums , ( hash : string , pathToFile : string ) => pathToFile ) ) ;
69
+ await deviceHashService . uploadHashFileToDevice ( currentShasums ) ;
70
+ }
71
+ }
72
+
42
73
private async connectLivesyncTool ( projectFilesPath : string , appIdentifier : string ) {
43
74
const adbPath = await this . $staticConfig . getAdbFilePath ( ) ;
44
75
await this . livesyncTool . connect ( {
@@ -50,8 +81,6 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
50
81
} ) ;
51
82
}
52
83
53
-
54
- @cache ( )
55
84
public getDeviceHashService ( appIdentifier : string ) : Mobile . IAndroidDeviceHashService {
56
85
const adb = this . $injector . resolve ( DeviceAndroidDebugBridge , { identifier : this . device . deviceInfo . identifier } ) ;
57
86
return this . $injector . resolve ( AndroidDeviceHashService , { adb, appIdentifier } ) ;
0 commit comments