1
- import * as deviceAppDataIdentifiers from "../../providers/device-app-data-provider" ;
2
1
import * as path from "path" ;
3
- import * as adls from "./android-device-livesync-service" ;
2
+ import { AndroidDeviceLiveSyncService } from "./android-device-livesync-service" ;
3
+ import { APP_FOLDER_NAME , SYNC_DIR_NAME , FULLSYNC_DIR_NAME } from "../../constants" ;
4
4
5
5
export class AndroidLiveSyncService implements IPlatformLiveSyncService {
6
6
constructor ( private $projectFilesManager : IProjectFilesManager ,
@@ -14,14 +14,13 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
14
14
public async fullSync ( syncInfo : IFullSyncInfo ) : Promise < ILiveSyncResultInfo > {
15
15
const projectData = syncInfo . projectData ;
16
16
const device = syncInfo . device ;
17
- const deviceLiveSyncService = this . $injector . resolve < adls . AndroidLiveSyncService > ( adls . AndroidLiveSyncService , { _device : device } ) ;
17
+ const deviceLiveSyncService = this . $injector . resolve < AndroidDeviceLiveSyncService > ( AndroidDeviceLiveSyncService , { _device : device } ) ;
18
18
const platformData = this . $platformsData . getPlatformData ( device . deviceInfo . platform , projectData ) ;
19
- const deviceAppData = this . $injector . resolve ( deviceAppDataIdentifiers . AndroidAppIdentifier ,
20
- { _appIdentifier : projectData . projectId , device, platform : device . deviceInfo . platform } ) ;
21
19
20
+ const deviceAppData = await this . getAppData ( syncInfo , deviceLiveSyncService ) ;
22
21
await deviceLiveSyncService . beforeLiveSyncAction ( deviceAppData ) ;
23
22
24
- const projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , "app" ) ;
23
+ const projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , APP_FOLDER_NAME ) ;
25
24
const localToDevicePaths = await this . $projectFilesManager . createLocalToDevicePaths ( deviceAppData , projectFilesPath , null , [ ] ) ;
26
25
await this . transferFiles ( deviceAppData , localToDevicePaths , projectFilesPath , true ) ;
27
26
@@ -34,8 +33,9 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
34
33
35
34
public async liveSyncWatchAction ( device : Mobile . IDevice , liveSyncInfo : ILiveSyncWatchInfo ) : Promise < ILiveSyncResultInfo > {
36
35
const projectData = liveSyncInfo . projectData ;
37
- const deviceAppData = this . $injector . resolve ( deviceAppDataIdentifiers . AndroidAppIdentifier ,
38
- { _appIdentifier : projectData . projectId , device, platform : device . deviceInfo . platform } ) ;
36
+ const syncInfo = _ . merge < IFullSyncInfo > ( { device, watch : true } , liveSyncInfo ) ;
37
+ const deviceLiveSyncService = this . $injector . resolve < AndroidDeviceLiveSyncService > ( AndroidDeviceLiveSyncService , { _device : device } ) ;
38
+ const deviceAppData = await this . getAppData ( syncInfo , deviceLiveSyncService ) ;
39
39
40
40
let modifiedLocalToDevicePaths : Mobile . ILocalToDevicePathData [ ] = [ ] ;
41
41
if ( liveSyncInfo . filesToSync . length ) {
@@ -52,7 +52,7 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
52
52
53
53
if ( existingFiles . length ) {
54
54
let platformData = this . $platformsData . getPlatformData ( device . deviceInfo . platform , projectData ) ;
55
- const projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , "app" ) ;
55
+ const projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , APP_FOLDER_NAME ) ;
56
56
let localToDevicePaths = await this . $projectFilesManager . createLocalToDevicePaths ( deviceAppData ,
57
57
projectFilesPath , mappedFiles , [ ] ) ;
58
58
modifiedLocalToDevicePaths . push ( ...localToDevicePaths ) ;
@@ -65,11 +65,11 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
65
65
let platformData = this . $platformsData . getPlatformData ( device . deviceInfo . platform , projectData ) ;
66
66
67
67
const mappedFiles = _ . map ( filePaths , filePath => this . $projectFilesProvider . mapFilePath ( filePath , device . deviceInfo . platform , projectData ) ) ;
68
- const projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , "app" ) ;
68
+ const projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , APP_FOLDER_NAME ) ;
69
69
let localToDevicePaths = await this . $projectFilesManager . createLocalToDevicePaths ( deviceAppData , projectFilesPath , mappedFiles , [ ] ) ;
70
70
modifiedLocalToDevicePaths . push ( ...localToDevicePaths ) ;
71
71
72
- const deviceLiveSyncService = this . $injector . resolve < INativeScriptDeviceLiveSyncService > ( adls . AndroidLiveSyncService , { _device : device } ) ;
72
+ const deviceLiveSyncService = this . $injector . resolve < INativeScriptDeviceLiveSyncService > ( AndroidDeviceLiveSyncService , { _device : device } ) ;
73
73
deviceLiveSyncService . removeFiles ( projectData . projectId , localToDevicePaths , projectData . projectId ) ;
74
74
}
75
75
@@ -80,12 +80,9 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
80
80
} ;
81
81
}
82
82
83
- public async refreshApplication (
84
- projectData : IProjectData ,
85
- liveSyncInfo : ILiveSyncResultInfo
86
- ) : Promise < void > {
83
+ public async refreshApplication ( projectData : IProjectData , liveSyncInfo : ILiveSyncResultInfo ) : Promise < void > {
87
84
if ( liveSyncInfo . isFullSync || liveSyncInfo . modifiedFilesData . length ) {
88
- let deviceLiveSyncService = this . $injector . resolve < INativeScriptDeviceLiveSyncService > ( adls . AndroidLiveSyncService , { _device : liveSyncInfo . deviceAppData . device } ) ;
85
+ let deviceLiveSyncService = this . $injector . resolve < INativeScriptDeviceLiveSyncService > ( AndroidDeviceLiveSyncService , { _device : liveSyncInfo . deviceAppData . device } ) ;
89
86
this . $logger . info ( "Refreshing application..." ) ;
90
87
await deviceLiveSyncService . refreshApplication ( projectData , liveSyncInfo ) ;
91
88
}
@@ -97,7 +94,21 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
97
94
} else {
98
95
await deviceAppData . device . fileSystem . transferFiles ( deviceAppData , localToDevicePaths ) ;
99
96
}
97
+ }
100
98
101
- console . log ( "TRANSFEREEDDDDDDD!!!!!!" ) ;
99
+ private async getAppData ( syncInfo : IFullSyncInfo , deviceLiveSyncService : IAndroidNativeScriptDeviceLiveSyncService ) : Promise < Mobile . IDeviceAppData > {
100
+ return {
101
+ appIdentifier : syncInfo . device . deviceInfo . identifier ,
102
+ device : syncInfo . device ,
103
+ platform : syncInfo . device . deviceInfo . platform ,
104
+ getDeviceProjectRootPath : async ( ) => {
105
+ const hashService = deviceLiveSyncService . getDeviceHashService ( syncInfo . device . deviceInfo . identifier ) ;
106
+ const hashFile = syncInfo . syncAllFiles ? null : await hashService . doesShasumFileExistsOnDevice ( ) ;
107
+ const syncFolderName = syncInfo . watch || hashFile ? SYNC_DIR_NAME : FULLSYNC_DIR_NAME ;
108
+ return `/data/local/tmp/${ syncInfo . device . deviceInfo . identifier } /${ syncFolderName } ` ;
109
+ } ,
110
+ isLiveSyncSupported : async ( ) => true
111
+ } ;
102
112
}
103
113
}
114
+ $injector . register ( "androidLiveSyncService" , AndroidLiveSyncService ) ;
0 commit comments