@@ -15,9 +15,7 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
15
15
"**/*.ts" ,
16
16
] ;
17
17
18
- private fastLivesyncFileExtensions = [ ".css" , ".xml" ] ;
19
-
20
- constructor ( $devicesServices : Mobile . IDevicesServices ,
18
+ constructor ( $devicesService : Mobile . IDevicesService ,
21
19
$fs : IFileSystem ,
22
20
$mobileHelper : Mobile . IMobileHelper ,
23
21
$localToDevicePathDataFactory : Mobile . ILocalToDevicePathDataFactory ,
@@ -51,9 +49,7 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
51
49
this . $projectDataService . initialize ( this . $projectData . projectDir ) ;
52
50
let frameworkVersion = this . $projectDataService . getValue ( platformData . frameworkPackageName ) . wait ( ) . version ;
53
51
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 ( ) ;
57
53
if ( shouldUpdate ) {
58
54
this . $platformService . updatePlatforms ( [ this . $devicePlatformsConstants . Android . toLowerCase ( ) ] ) . wait ( ) ;
59
55
} else {
@@ -103,8 +99,6 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
103
99
mappedFilePath = path . join ( platformData . platformProjectService . getAppResourcesDestinationDirectoryPath ( ) . wait ( ) , appResourcesRelativePath ) ;
104
100
}
105
101
106
- this . sendPageReloadMessage ( path . extname ( mappedFilePath ) , platform ) . wait ( ) ;
107
-
108
102
return mappedFilePath ;
109
103
} ) . future < string > ( ) ( ) ;
110
104
} ;
@@ -113,12 +107,6 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
113
107
return path . join ( constants . APP_FOLDER_NAME , path . dirname ( projectFile . split ( `/${ constants . APP_FOLDER_NAME } /` ) [ 1 ] ) ) ;
114
108
} ;
115
109
116
- let shouldRestartApplication = ( localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) : IFuture < boolean > => {
117
- return ( ( ) => {
118
- return false ;
119
- } ) . future < boolean > ( ) ( ) ;
120
- } ;
121
-
122
110
let watchGlob = path . join ( this . $projectData . projectDir , constants . APP_FOLDER_NAME ) ;
123
111
124
112
let platformSpecificLiveSyncServices : IDictionary < any > = {
@@ -128,20 +116,51 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
128
116
129
117
let localProjectRootPath = platform . toLowerCase ( ) === "ios" ? platformData . appDestinationDirectoryPath : null ;
130
118
131
- this . sync ( platform ,
132
- this . $projectData . projectId ,
133
- projectFilesPath ,
134
- this . excludedProjectDirsAndFiles ,
135
- watchGlob ,
136
- platformSpecificLiveSyncServices ,
137
- notInstalledAppOnDeviceAction ,
138
- notRunningiOSSimulatorAction ,
139
- localProjectRootPath ,
140
- beforeLiveSyncAction ,
141
- beforeBatchLiveSyncAction ,
142
- iOSSimulatorRelativeToProjectBasePathAction ,
143
- shouldRestartApplication
144
- ) . wait ( ) ;
119
+ let fastLivesyncFileExtensions = [ ".css" , ".xml" ] ;
120
+ let canExecuteFastLiveSync = ( filePath : string ) => _ . contains ( fastLivesyncFileExtensions , path . extname ( filePath ) ) ;
121
+
122
+ let fastLiveSync = ( filePath : string ) => {
123
+ return ( ( ) => {
124
+ this . $platformService . preparePlatform ( platform ) . wait ( ) ;
125
+ let mappedFilePath = beforeBatchLiveSyncAction ( filePath ) . wait ( ) ;
126
+
127
+ if ( this . shouldSynciOSSimulator ( platform ) . wait ( ) ) {
128
+ let platformSpecificUsbLiveSyncService = < IiOSUsbLiveSyncService > this . resolvePlatformSpecificLiveSyncService ( platform || this . $devicesService . platform , null , platformSpecificLiveSyncServices ) ;
129
+ platformSpecificUsbLiveSyncService . sendPageReloadMessageToSimulator ( ) . wait ( ) ;
130
+ } else {
131
+ let deviceAppData = this . $deviceAppDataFactory . create ( this . $projectData . projectId , this . $mobileHelper . normalizePlatformName ( platform ) ) ;
132
+ let localToDevicePaths = this . createLocalToDevicePaths ( platform , this . $projectData . projectId , projectFilesPath , [ mappedFilePath ] ) ;
133
+
134
+ let devices = this . $devicesService . getDeviceInstances ( ) ;
135
+ _ . each ( devices , ( device : Mobile . IDevice ) => {
136
+ this . transferFiles ( device , deviceAppData , localToDevicePaths ) ;
137
+ let platformSpecificUsbLiveSyncService = this . resolvePlatformSpecificLiveSyncService ( platform || this . $devicesService . platform , device , platformSpecificLiveSyncServices ) ;
138
+ return platformSpecificUsbLiveSyncService . sendPageReloadMessageToDevice ( deviceAppData ) ;
139
+ } ) ;
140
+
141
+ this . $dispatcher . dispatch ( ( ) => Future . fromResult ( ) ) ;
142
+ }
143
+ } ) . future < void > ( ) ( ) ;
144
+ } ;
145
+
146
+ let liveSyncData = {
147
+ platform : platform ,
148
+ appIdentifier : this . $projectData . projectId ,
149
+ projectFilesPath : projectFilesPath ,
150
+ excludedProjectDirsAndFiles : this . excludedProjectDirsAndFiles ,
151
+ watchGlob : watchGlob ,
152
+ platformSpecificLiveSyncServices : platformSpecificLiveSyncServices ,
153
+ notInstalledAppOnDeviceAction : notInstalledAppOnDeviceAction ,
154
+ notRunningiOSSimulatorAction : notRunningiOSSimulatorAction ,
155
+ localProjectRootPath : localProjectRootPath ,
156
+ beforeLiveSyncAction : beforeLiveSyncAction ,
157
+ beforeBatchLiveSyncAction : beforeBatchLiveSyncAction ,
158
+ iOSSimulatorRelativeToProjectBasePathAction : iOSSimulatorRelativeToProjectBasePathAction ,
159
+ canExecuteFastLiveSync : canExecuteFastLiveSync ,
160
+ fastLiveSync : fastLiveSync
161
+ } ;
162
+
163
+ this . sync ( liveSyncData ) . wait ( ) ;
145
164
} ) . future < void > ( ) ( ) ;
146
165
}
147
166
@@ -159,28 +178,10 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
159
178
160
179
return platformSpecificUsbLiveSyncService ;
161
180
}
162
-
163
- private sendPageReloadMessage ( fileExtension : string , platform : string ) : IFuture < void > {
164
- return ( ( ) => {
165
- if ( _ . contains ( this . fastLivesyncFileExtensions , fileExtension ) ) {
166
- let platformLowerCase = platform ? platform . toLowerCase ( ) : null ;
167
- if ( this . $options . emulator && platformLowerCase === "ios" ) {
168
- let platformSpecificUsbLiveSyncService = this . resolveUsbLiveSyncService ( platform || this . $devicesServices . platform , null ) ;
169
- platformSpecificUsbLiveSyncService . sendPageReloadMessageToSimulator ( ) . wait ( ) ;
170
- } else {
171
- let devices = this . $devicesServices . getDevices ( ) ;
172
- _ . each ( devices , ( device : Mobile . IDevice ) => {
173
- let platformSpecificUsbLiveSyncService = this . resolveUsbLiveSyncService ( platform || this . $devicesServices . platform , device ) ;
174
- return platformSpecificUsbLiveSyncService . sendPageReloadMessageToDevice ( ) ;
175
- } ) ;
176
- }
177
- }
178
- } ) . future < void > ( ) ( ) ;
179
- }
180
181
}
181
182
$injector . register ( "usbLiveSyncService" , UsbLiveSyncService ) ;
182
183
183
- export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncService {
184
+ export class IOSUsbLiveSyncService implements IiOSUsbLiveSyncService {
184
185
private static BACKEND_PORT = 18181 ;
185
186
private currentPageReloadId = 0 ;
186
187
@@ -197,7 +198,7 @@ export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncServic
197
198
return this . device . applicationManager . restartApplication ( deviceAppData . appIdentifier ) ;
198
199
}
199
200
200
- public sendPageReloadMessageToDevice ( ) : IFuture < void > {
201
+ public sendPageReloadMessageToDevice ( deviceAppData : Mobile . IDeviceAppData ) : IFuture < void > {
201
202
return ( ( ) => {
202
203
let timeout = 9000 ;
203
204
this . $iOSSocketRequestExecutor . executeAttachRequest ( this . device , timeout ) . wait ( ) ;
@@ -226,12 +227,13 @@ export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncServic
226
227
$injector . register ( "iosUsbLiveSyncServiceLocator" , { factory : IOSUsbLiveSyncService } ) ;
227
228
228
229
export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib . AndroidLiveSyncService implements IPlatformSpecificUsbLiveSyncService {
230
+ private static BACKEND_PORT = 18181 ;
231
+
229
232
constructor ( _device : Mobile . IDevice ,
230
233
$fs : IFileSystem ,
231
234
$mobileHelper : Mobile . IMobileHelper ,
232
235
private $options : IOptions ) {
233
236
super ( < Mobile . IAndroidDevice > _device , $fs , $mobileHelper ) ;
234
-
235
237
}
236
238
237
239
public restartApplication ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) : IFuture < void > {
@@ -261,12 +263,15 @@ export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.Android
261
263
} ) . future < void > ( ) ( ) ;
262
264
}
263
265
264
- public sendPageReloadMessageToSimulator ( ) : IFuture < void > {
265
- return Future . fromResult ( ) ;
266
- }
267
-
268
- public sendPageReloadMessageToDevice ( ) : IFuture < void > {
269
- return Future . fromResult ( ) ;
266
+ public sendPageReloadMessageToDevice ( deviceAppData : Mobile . IDeviceAppData ) : IFuture < void > {
267
+ return ( ( ) => {
268
+ let socket = new net . Socket ( ) ;
269
+ socket . connect ( AndroidUsbLiveSyncService . BACKEND_PORT , '127.0.0.1' , ( ) => {
270
+ socket . write ( new Buffer ( [ 0 , 0 , 0 , 1 , 1 ] ) ) ;
271
+ socket . destroy ( ) ;
272
+ } ) ;
273
+ this . device . adb . executeCommand ( [ "forward" , `tcp:${ AndroidUsbLiveSyncService . BACKEND_PORT . toString ( ) } ` , `localabstract:${ deviceAppData . appIdentifier } -livesync` ] ) . wait ( ) ;
274
+ } ) . future < void > ( ) ( ) ;
270
275
}
271
276
}
272
277
$injector . register ( "androidUsbLiveSyncServiceLocator" , { factory : AndroidUsbLiveSyncService } ) ;
0 commit comments