@@ -15,9 +15,7 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
1515 "**/*.ts" ,
1616 ] ;
1717
18- private fastLivesyncFileExtensions = [ ".css" , ".xml" ] ;
19-
20- constructor ( $devicesServices : Mobile . IDevicesServices ,
18+ constructor ( $devicesService : Mobile . IDevicesService ,
2119 $fs : IFileSystem ,
2220 $mobileHelper : Mobile . IMobileHelper ,
2321 $localToDevicePathDataFactory : Mobile . ILocalToDevicePathDataFactory ,
@@ -51,9 +49,7 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
5149 this . $projectDataService . initialize ( this . $projectData . projectDir ) ;
5250 let frameworkVersion = this . $projectDataService . getValue ( platformData . frameworkPackageName ) . wait ( ) . version ;
5351 if ( semver . lt ( frameworkVersion , "1.2.1" ) ) {
54- let shouldUpdate = this . $prompter . confirm (
55- "You need Android Runtime 1.2.1 or later for LiveSync to work properly. Do you want to update your runtime now?"
56- ) . wait ( ) ;
52+ let shouldUpdate = this . $prompter . confirm ( "You need Android Runtime 1.2.1 or later for LiveSync to work properly. Do you want to update your runtime now?" ) . wait ( ) ;
5753 if ( shouldUpdate ) {
5854 this . $platformService . updatePlatforms ( [ this . $devicePlatformsConstants . Android . toLowerCase ( ) ] ) . wait ( ) ;
5955 } else {
@@ -76,7 +72,7 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
7672 let notRunningiOSSimulatorAction = ( ) : IFuture < boolean > => {
7773 return ( ( ) => {
7874 this . $platformService . deployOnEmulator ( this . $devicePlatformsConstants . iOS . toLowerCase ( ) ) . wait ( ) ;
79- return false ;
75+ return false ;
8076 } ) . future < boolean > ( ) ( ) ;
8177 } ;
8278
@@ -106,8 +102,6 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
106102 mappedFilePath = path . join ( platformData . platformProjectService . getAppResourcesDestinationDirectoryPath ( ) . wait ( ) , appResourcesRelativePath ) ;
107103 }
108104
109- this . sendPageReloadMessage ( path . extname ( mappedFilePath ) , platform ) . wait ( ) ;
110-
111105 return mappedFilePath ;
112106 } ) . future < string > ( ) ( ) ;
113107 } ;
@@ -116,12 +110,6 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
116110 return path . join ( constants . APP_FOLDER_NAME , path . dirname ( projectFile . split ( `/${ constants . APP_FOLDER_NAME } /` ) [ 1 ] ) ) ;
117111 } ;
118112
119- let shouldRestartApplication = ( localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) : IFuture < boolean > => {
120- return ( ( ) => {
121- return false ;
122- } ) . future < boolean > ( ) ( ) ;
123- } ;
124-
125113 let watchGlob = path . join ( this . $projectData . projectDir , constants . APP_FOLDER_NAME ) ;
126114
127115 let platformSpecificLiveSyncServices : IDictionary < any > = {
@@ -131,20 +119,51 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
131119
132120 let localProjectRootPath = platform . toLowerCase ( ) === "ios" ? platformData . appDestinationDirectoryPath : null ;
133121
134- this . sync ( platform ,
135- this . $projectData . projectId ,
136- projectFilesPath ,
137- this . excludedProjectDirsAndFiles ,
138- watchGlob ,
139- platformSpecificLiveSyncServices ,
140- notInstalledAppOnDeviceAction ,
141- notRunningiOSSimulatorAction ,
142- localProjectRootPath ,
143- beforeLiveSyncAction ,
144- beforeBatchLiveSyncAction ,
145- iOSSimulatorRelativeToProjectBasePathAction ,
146- shouldRestartApplication
147- ) . wait ( ) ;
122+ let fastLivesyncFileExtensions = [ ".css" , ".xml" ] ;
123+ let canExecuteFastLiveSync = ( filePath : string ) => _ . contains ( fastLivesyncFileExtensions , path . extname ( filePath ) ) ;
124+
125+ let fastLiveSync = ( filePath : string ) => {
126+ return ( ( ) => {
127+ this . $platformService . preparePlatform ( platform ) . wait ( ) ;
128+ let mappedFilePath = beforeBatchLiveSyncAction ( filePath ) . wait ( ) ;
129+
130+ if ( this . shouldSynciOSSimulator ( platform ) . wait ( ) ) {
131+ let platformSpecificUsbLiveSyncService = < IiOSUsbLiveSyncService > this . resolvePlatformSpecificLiveSyncService ( platform || this . $devicesService . platform , null , platformSpecificLiveSyncServices ) ;
132+ platformSpecificUsbLiveSyncService . sendPageReloadMessageToSimulator ( ) . wait ( ) ;
133+ } else {
134+ let deviceAppData = this . $deviceAppDataFactory . create ( this . $projectData . projectId , this . $mobileHelper . normalizePlatformName ( platform ) ) ;
135+ let localToDevicePaths = this . createLocalToDevicePaths ( platform , this . $projectData . projectId , projectFilesPath , [ mappedFilePath ] ) ;
136+
137+ let devices = this . $devicesService . getDeviceInstances ( ) ;
138+ _ . each ( devices , ( device : Mobile . IDevice ) => {
139+ this . transferFiles ( device , deviceAppData , localToDevicePaths ) ;
140+ let platformSpecificUsbLiveSyncService = this . resolvePlatformSpecificLiveSyncService ( platform || this . $devicesService . platform , device , platformSpecificLiveSyncServices ) ;
141+ return platformSpecificUsbLiveSyncService . sendPageReloadMessageToDevice ( deviceAppData ) ;
142+ } ) ;
143+
144+ this . $dispatcher . dispatch ( ( ) => Future . fromResult ( ) ) ;
145+ }
146+ } ) . future < void > ( ) ( ) ;
147+ } ;
148+
149+ let liveSyncData = {
150+ platform : platform ,
151+ appIdentifier : this . $projectData . projectId ,
152+ projectFilesPath : projectFilesPath ,
153+ excludedProjectDirsAndFiles : this . excludedProjectDirsAndFiles ,
154+ watchGlob : watchGlob ,
155+ platformSpecificLiveSyncServices : platformSpecificLiveSyncServices ,
156+ notInstalledAppOnDeviceAction : notInstalledAppOnDeviceAction ,
157+ notRunningiOSSimulatorAction : notRunningiOSSimulatorAction ,
158+ localProjectRootPath : localProjectRootPath ,
159+ beforeLiveSyncAction : beforeLiveSyncAction ,
160+ beforeBatchLiveSyncAction : beforeBatchLiveSyncAction ,
161+ iOSSimulatorRelativeToProjectBasePathAction : iOSSimulatorRelativeToProjectBasePathAction ,
162+ canExecuteFastLiveSync : canExecuteFastLiveSync ,
163+ fastLiveSync : fastLiveSync
164+ } ;
165+
166+ this . sync ( liveSyncData ) . wait ( ) ;
148167 } ) . future < void > ( ) ( ) ;
149168 }
150169
@@ -162,28 +181,10 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
162181
163182 return platformSpecificUsbLiveSyncService ;
164183 }
165-
166- private sendPageReloadMessage ( fileExtension : string , platform : string ) : IFuture < void > {
167- return ( ( ) => {
168- if ( _ . contains ( this . fastLivesyncFileExtensions , fileExtension ) ) {
169- let platformLowerCase = platform ? platform . toLowerCase ( ) : null ;
170- if ( this . $options . emulator && platformLowerCase === "ios" ) {
171- let platformSpecificUsbLiveSyncService = this . resolveUsbLiveSyncService ( platform || this . $devicesServices . platform , null ) ;
172- platformSpecificUsbLiveSyncService . sendPageReloadMessageToSimulator ( ) . wait ( ) ;
173- } else {
174- let devices = this . $devicesServices . getDevices ( ) ;
175- _ . each ( devices , ( device : Mobile . IDevice ) => {
176- let platformSpecificUsbLiveSyncService = this . resolveUsbLiveSyncService ( platform || this . $devicesServices . platform , device ) ;
177- return platformSpecificUsbLiveSyncService . sendPageReloadMessageToDevice ( ) ;
178- } ) ;
179- }
180- }
181- } ) . future < void > ( ) ( ) ;
182- }
183184}
184185$injector . register ( "usbLiveSyncService" , UsbLiveSyncService ) ;
185186
186- export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncService {
187+ export class IOSUsbLiveSyncService implements IiOSUsbLiveSyncService {
187188 private static BACKEND_PORT = 18181 ;
188189 private currentPageReloadId = 0 ;
189190
@@ -200,7 +201,7 @@ export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncServic
200201 return this . device . applicationManager . restartApplication ( deviceAppData . appIdentifier ) ;
201202 }
202203
203- public sendPageReloadMessageToDevice ( ) : IFuture < void > {
204+ public sendPageReloadMessageToDevice ( deviceAppData : Mobile . IDeviceAppData ) : IFuture < void > {
204205 return ( ( ) => {
205206 let timeout = 9000 ;
206207 this . $iOSSocketRequestExecutor . executeAttachRequest ( this . device , timeout ) . wait ( ) ;
@@ -229,12 +230,13 @@ export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncServic
229230$injector . register ( "iosUsbLiveSyncServiceLocator" , { factory : IOSUsbLiveSyncService } ) ;
230231
231232export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib . AndroidLiveSyncService implements IPlatformSpecificUsbLiveSyncService {
233+ private static BACKEND_PORT = 18181 ;
234+
232235 constructor ( _device : Mobile . IDevice ,
233236 $fs : IFileSystem ,
234237 $mobileHelper : Mobile . IMobileHelper ,
235238 private $options : IOptions ) {
236239 super ( < Mobile . IAndroidDevice > _device , $fs , $mobileHelper ) ;
237-
238240 }
239241
240242 public restartApplication ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) : IFuture < void > {
@@ -264,12 +266,15 @@ export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.Android
264266 } ) . future < void > ( ) ( ) ;
265267 }
266268
267- public sendPageReloadMessageToSimulator ( ) : IFuture < void > {
268- return Future . fromResult ( ) ;
269- }
270-
271- public sendPageReloadMessageToDevice ( ) : IFuture < void > {
272- return Future . fromResult ( ) ;
269+ public sendPageReloadMessageToDevice ( deviceAppData : Mobile . IDeviceAppData ) : IFuture < void > {
270+ return ( ( ) => {
271+ let socket = new net . Socket ( ) ;
272+ socket . connect ( AndroidUsbLiveSyncService . BACKEND_PORT , '127.0.0.1' , ( ) => {
273+ socket . write ( new Buffer ( [ 0 , 0 , 0 , 1 , 1 ] ) ) ;
274+ socket . destroy ( ) ;
275+ } ) ;
276+ this . device . adb . executeCommand ( [ "forward" , `tcp:${ AndroidUsbLiveSyncService . BACKEND_PORT . toString ( ) } ` , `localabstract:${ deviceAppData . appIdentifier } -livesync` ] ) . wait ( ) ;
277+ } ) . future < void > ( ) ( ) ;
273278 }
274279}
275280$injector . register ( "androidUsbLiveSyncServiceLocator" , { factory : AndroidUsbLiveSyncService } ) ;
0 commit comments