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