1
1
import { DeviceLiveSyncServiceBase } from './device-livesync-service-base' ;
2
- import { AndroidDeviceHashService } from "../../common/mobile/android/android-device-hash-service" ;
3
2
4
3
export abstract class AndroidDeviceLiveSyncServiceBase extends DeviceLiveSyncServiceBase {
5
- private deviceHashServices : IDictionary < Mobile . IAndroidDeviceHashService > ;
6
-
7
4
constructor ( protected $injector : IInjector ,
8
5
protected $platformsData : IPlatformsData ,
9
6
protected $filesHashService : IFilesHashService ,
10
7
protected $logger : ILogger ,
11
8
protected device : Mobile . IAndroidDevice ) {
12
9
super ( $platformsData , device ) ;
13
- this . deviceHashServices = { } ;
14
10
}
15
11
16
12
public abstract async transferFilesOnDevice ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) : Promise < void > ;
17
13
public abstract async transferDirectoryOnDevice ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string ) : Promise < void > ;
18
14
19
- public getDeviceHashService ( appIdentifier : string ) : Mobile . IAndroidDeviceHashService {
20
- const key = `${ this . device . deviceInfo . identifier } ${ appIdentifier } ` ;
21
- if ( ! this . deviceHashServices [ key ] ) {
22
- const deviceHashService = this . $injector . resolve ( AndroidDeviceHashService , { adb : this . device . adb , appIdentifier } ) ;
23
- this . deviceHashServices [ key ] = deviceHashService ;
24
- }
25
-
26
- return this . deviceHashServices [ key ] ;
27
- }
28
-
29
15
public async transferFiles ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string , projectData : IProjectData , liveSyncDeviceInfo : ILiveSyncDeviceInfo , options : ITransferFilesOptions ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
30
- const deviceHashService = this . getDeviceHashService ( deviceAppData . appIdentifier ) ;
16
+ const deviceHashService = this . device . fileSystem . getDeviceHashService ( deviceAppData . appIdentifier ) ;
31
17
const currentHashes = await deviceHashService . generateHashesFromLocalToDevicePaths ( localToDevicePaths ) ;
32
18
const transferredFiles = await this . transferFilesCore ( deviceAppData , localToDevicePaths , projectFilesPath , currentHashes , options ) ;
33
- await this . updateHashes ( deviceAppData , currentHashes , projectData , liveSyncDeviceInfo ) ;
19
+ await this . device . fileSystem . updateHashesOnDevice ( currentHashes , deviceAppData . appIdentifier ) ;
34
20
return transferredFiles ;
35
21
}
36
22
37
23
private async transferFilesCore ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string , currentHashes : IStringDictionary , options : ITransferFilesOptions ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
38
24
if ( options . force && options . isFullSync ) {
39
- const hashFileDevicePath = this . getDeviceHashService ( deviceAppData . appIdentifier ) . hashFileDevicePath ;
25
+ const hashFileDevicePath = this . device . fileSystem . getDeviceHashService ( deviceAppData . appIdentifier ) . hashFileDevicePath ;
40
26
await this . device . fileSystem . deleteFile ( hashFileDevicePath , deviceAppData . appIdentifier ) ;
41
27
this . $logger . trace ( "Before transfer directory on device " , localToDevicePaths ) ;
42
28
await this . transferDirectoryOnDevice ( deviceAppData , localToDevicePaths , projectFilesPath ) ;
@@ -59,27 +45,11 @@ export abstract class AndroidDeviceLiveSyncServiceBase extends DeviceLiveSyncSer
59
45
}
60
46
61
47
private async getChangedLocalToDevicePaths ( appIdentifier : string , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , currentHashes : IStringDictionary ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
62
- const deviceHashService = this . getDeviceHashService ( appIdentifier ) ;
48
+ const deviceHashService = this . device . fileSystem . getDeviceHashService ( appIdentifier ) ;
63
49
const oldHashes = ( await deviceHashService . getShasumsFromDevice ( ) ) || { } ;
64
50
const changedHashes = deviceHashService . getChangedShasums ( oldHashes , currentHashes ) ;
65
51
const changedFiles = _ . keys ( changedHashes ) ;
66
52
const changedLocalToDevicePaths = localToDevicePaths . filter ( localToDevicePathData => changedFiles . indexOf ( localToDevicePathData . getLocalPath ( ) ) >= 0 ) ;
67
53
return changedLocalToDevicePaths ;
68
54
}
69
-
70
- private async updateHashes ( deviceAppData : Mobile . IDeviceAppData , currentHashes : IStringDictionary , projectData : IProjectData , liveSyncDeviceInfo : ILiveSyncDeviceInfo ) : Promise < void > {
71
- const hashes = await this . updateHashesOnDevice ( deviceAppData , currentHashes , projectData , liveSyncDeviceInfo ) ;
72
- this . updateLocalHashes ( hashes , deviceAppData , projectData , liveSyncDeviceInfo ) ;
73
- }
74
-
75
- private async updateHashesOnDevice ( deviceAppData : Mobile . IDeviceAppData , currentHashes : IStringDictionary , projectData : IProjectData , liveSyncDeviceInfo : ILiveSyncDeviceInfo ) : Promise < IStringDictionary > {
76
- const deviceHashService = this . getDeviceHashService ( deviceAppData . appIdentifier ) ;
77
- await deviceHashService . uploadHashFileToDevice ( currentHashes ) ;
78
- return currentHashes ;
79
- }
80
-
81
- private updateLocalHashes ( hashes : IStringDictionary , deviceAppData : Mobile . IDeviceAppData , projectData : IProjectData , liveSyncDeviceInfo : ILiveSyncDeviceInfo ) : void {
82
- const hashFilePath = liveSyncDeviceInfo . outputPath || this . $platformsData . getPlatformData ( deviceAppData . platform , projectData ) . deviceBuildOutputPath ;
83
- this . $filesHashService . saveHashes ( hashes , hashFilePath ) ;
84
- }
85
55
}
0 commit comments