@@ -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 {
@@ -76,7 +72,7 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
76
72
let notRunningiOSSimulatorAction = ( ) : IFuture < boolean > => {
77
73
return ( ( ) => {
78
74
this . $platformService . deployOnEmulator ( this . $devicePlatformsConstants . iOS . toLowerCase ( ) ) . wait ( ) ;
79
- return false ;
75
+ return false ;
80
76
} ) . future < boolean > ( ) ( ) ;
81
77
} ;
82
78
@@ -106,8 +102,6 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
106
102
mappedFilePath = path . join ( platformData . platformProjectService . getAppResourcesDestinationDirectoryPath ( ) . wait ( ) , appResourcesRelativePath ) ;
107
103
}
108
104
109
- this . sendPageReloadMessage ( path . extname ( mappedFilePath ) , platform ) . wait ( ) ;
110
-
111
105
return mappedFilePath ;
112
106
} ) . future < string > ( ) ( ) ;
113
107
} ;
@@ -116,12 +110,6 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
116
110
return path . join ( constants . APP_FOLDER_NAME , path . dirname ( projectFile . split ( `/${ constants . APP_FOLDER_NAME } /` ) [ 1 ] ) ) ;
117
111
} ;
118
112
119
- let shouldRestartApplication = ( localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) : IFuture < boolean > => {
120
- return ( ( ) => {
121
- return false ;
122
- } ) . future < boolean > ( ) ( ) ;
123
- } ;
124
-
125
113
let watchGlob = path . join ( this . $projectData . projectDir , constants . APP_FOLDER_NAME ) ;
126
114
127
115
let platformSpecificLiveSyncServices : IDictionary < any > = {
@@ -131,20 +119,51 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
131
119
132
120
let localProjectRootPath = platform . toLowerCase ( ) === "ios" ? platformData . appDestinationDirectoryPath : null ;
133
121
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 ( ) ;
148
167
} ) . future < void > ( ) ( ) ;
149
168
}
150
169
@@ -162,28 +181,10 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
162
181
163
182
return platformSpecificUsbLiveSyncService ;
164
183
}
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
- }
183
184
}
184
185
$injector . register ( "usbLiveSyncService" , UsbLiveSyncService ) ;
185
186
186
- export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncService {
187
+ export class IOSUsbLiveSyncService implements IiOSUsbLiveSyncService {
187
188
private static BACKEND_PORT = 18181 ;
188
189
private currentPageReloadId = 0 ;
189
190
@@ -200,7 +201,7 @@ export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncServic
200
201
return this . device . applicationManager . restartApplication ( deviceAppData . appIdentifier ) ;
201
202
}
202
203
203
- public sendPageReloadMessageToDevice ( ) : IFuture < void > {
204
+ public sendPageReloadMessageToDevice ( deviceAppData : Mobile . IDeviceAppData ) : IFuture < void > {
204
205
return ( ( ) => {
205
206
let timeout = 9000 ;
206
207
this . $iOSSocketRequestExecutor . executeAttachRequest ( this . device , timeout ) . wait ( ) ;
@@ -229,12 +230,13 @@ export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncServic
229
230
$injector . register ( "iosUsbLiveSyncServiceLocator" , { factory : IOSUsbLiveSyncService } ) ;
230
231
231
232
export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib . AndroidLiveSyncService implements IPlatformSpecificUsbLiveSyncService {
233
+ private static BACKEND_PORT = 18181 ;
234
+
232
235
constructor ( _device : Mobile . IDevice ,
233
236
$fs : IFileSystem ,
234
237
$mobileHelper : Mobile . IMobileHelper ,
235
238
private $options : IOptions ) {
236
239
super ( < Mobile . IAndroidDevice > _device , $fs , $mobileHelper ) ;
237
-
238
240
}
239
241
240
242
public restartApplication ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) : IFuture < void > {
@@ -264,12 +266,15 @@ export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.Android
264
266
} ) . future < void > ( ) ( ) ;
265
267
}
266
268
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 > ( ) ( ) ;
273
278
}
274
279
}
275
280
$injector . register ( "androidUsbLiveSyncServiceLocator" , { factory : AndroidUsbLiveSyncService } ) ;
0 commit comments