1- import * as deviceAppDataIdentifiers from "../../providers/device-app-data-provider" ;
21import * 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" ;
44
55export class AndroidLiveSyncService implements IPlatformLiveSyncService {
66constructor ( private $projectFilesManager : IProjectFilesManager ,
@@ -14,14 +14,13 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
1414public async fullSync ( syncInfo : IFullSyncInfo ) : Promise < ILiveSyncResultInfo > {
1515const projectData = syncInfo . projectData ;
1616const 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 } ) ;
1818const 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 } ) ;
2119
20+ const deviceAppData = await this . getAppData ( syncInfo , deviceLiveSyncService ) ;
2221await deviceLiveSyncService . beforeLiveSyncAction ( deviceAppData ) ;
2322
24- const projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , "app" ) ;
23+ const projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , APP_FOLDER_NAME ) ;
2524const localToDevicePaths = await this . $projectFilesManager . createLocalToDevicePaths ( deviceAppData , projectFilesPath , null , [ ] ) ;
2625await this . transferFiles ( deviceAppData , localToDevicePaths , projectFilesPath , true ) ;
2726
@@ -34,8 +33,9 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
3433
3534public async liveSyncWatchAction ( device : Mobile . IDevice , liveSyncInfo : ILiveSyncWatchInfo ) : Promise < ILiveSyncResultInfo > {
3635const 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 ) ;
3939
4040let modifiedLocalToDevicePaths : Mobile . ILocalToDevicePathData [ ] = [ ] ;
4141if ( liveSyncInfo . filesToSync . length ) {
@@ -52,7 +52,7 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
5252
5353if ( existingFiles . length ) {
5454let 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 ) ;
5656let localToDevicePaths = await this . $projectFilesManager . createLocalToDevicePaths ( deviceAppData ,
5757projectFilesPath , mappedFiles , [ ] ) ;
5858modifiedLocalToDevicePaths . push ( ...localToDevicePaths ) ;
@@ -65,11 +65,11 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
6565let platformData = this . $platformsData . getPlatformData ( device . deviceInfo . platform , projectData ) ;
6666
6767const 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 ) ;
6969let localToDevicePaths = await this . $projectFilesManager . createLocalToDevicePaths ( deviceAppData , projectFilesPath , mappedFiles , [ ] ) ;
7070modifiedLocalToDevicePaths . push ( ...localToDevicePaths ) ;
7171
72- const deviceLiveSyncService = this . $injector . resolve < INativeScriptDeviceLiveSyncService > ( adls . AndroidLiveSyncService , { _device : device } ) ;
72+ const deviceLiveSyncService = this . $injector . resolve < INativeScriptDeviceLiveSyncService > ( AndroidDeviceLiveSyncService , { _device : device } ) ;
7373deviceLiveSyncService . removeFiles ( projectData . projectId , localToDevicePaths , projectData . projectId ) ;
7474}
7575
@@ -80,12 +80,9 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
8080} ;
8181}
8282
83- public async refreshApplication (
84- projectData : IProjectData ,
85- liveSyncInfo : ILiveSyncResultInfo
86- ) : Promise < void > {
83+ public async refreshApplication ( projectData : IProjectData , liveSyncInfo : ILiveSyncResultInfo ) : Promise < void > {
8784if ( 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 } ) ;
8986this . $logger . info ( "Refreshing application..." ) ;
9087await deviceLiveSyncService . refreshApplication ( projectData , liveSyncInfo ) ;
9188}
@@ -97,7 +94,21 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
9794} else {
9895await deviceAppData . device . fileSystem . transferFiles ( deviceAppData , localToDevicePaths ) ;
9996}
97+ }
10098
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+ } ;
102112}
103113}
114+ $injector . register ( "androidLiveSyncService" , AndroidLiveSyncService ) ;
0 commit comments