@@ -25,7 +25,6 @@ class LiveSyncServiceBase implements ILiveSyncServiceBase {
2525 private $projectFilesProvider : IProjectFilesProvider ,
2626 private $liveSyncProvider : ILiveSyncProvider ,
2727 private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
28- private $hostInfo : IHostInfo ,
2928 private $dispatcher : IFutureDispatcher ) {
3029 this . fileHashes = Object . create ( null ) ;
3130 }
@@ -176,53 +175,45 @@ class LiveSyncServiceBase implements ILiveSyncServiceBase {
176175 return ( ( ) => {
177176 let shouldRefreshApplication = true ;
178177 let deviceAppData = this . $deviceAppDataFactory . create ( appIdentifier , this . $mobileHelper . normalizePlatformName ( platform ) , device , liveSyncOptions ) ;
179- if ( deviceAppData . isLiveSyncSupported ( ) . wait ( ) ) {
180- let platformLiveSyncService = this . resolvePlatformLiveSyncService ( platform , device ) ;
178+ let platformLiveSyncService = this . resolvePlatformLiveSyncService ( platform , device ) ;
181179
182- if ( platformLiveSyncService . beforeLiveSyncAction ) {
183- platformLiveSyncService . beforeLiveSyncAction ( deviceAppData ) . wait ( ) ;
184- }
180+ if ( platformLiveSyncService . beforeLiveSyncAction ) {
181+ platformLiveSyncService . beforeLiveSyncAction ( deviceAppData ) . wait ( ) ;
182+ }
185183
186- // Not installed application
187- device . applicationManager . checkForApplicationUpdates ( ) . wait ( ) ;
184+ // Not installed application
185+ device . applicationManager . checkForApplicationUpdates ( ) . wait ( ) ;
188186
189- let wasInstalled = true ;
190- if ( ! device . applicationManager . isApplicationInstalled ( appIdentifier ) . wait ( ) && ! this . $options . companion ) {
191- this . $logger . warn ( `The application with id "${ appIdentifier } " is not installed on device with identifier ${ device . deviceInfo . identifier } .` ) ;
192- if ( ! packageFilePath ) {
193- packageFilePath = this . $liveSyncProvider . buildForDevice ( device ) . wait ( ) ;
194- }
195- device . applicationManager . installApplication ( packageFilePath ) . wait ( ) ;
187+ let wasInstalled = true ;
188+ if ( ! device . applicationManager . isApplicationInstalled ( appIdentifier ) . wait ( ) ) {
189+ this . $logger . warn ( `The application with id "${ appIdentifier } " is not installed on device with identifier ${ device . deviceInfo . identifier } .` ) ;
190+ if ( ! packageFilePath ) {
191+ packageFilePath = this . $liveSyncProvider . buildForDevice ( device ) . wait ( ) ;
192+ }
193+ device . applicationManager . installApplication ( packageFilePath ) . wait ( ) ;
196194
197- if ( platformLiveSyncService . afterInstallApplicationAction ) {
198- let localToDevicePaths = this . $projectFilesManager . createLocalToDevicePaths ( deviceAppData , projectFilesPath , filesToSync , data . excludedProjectDirsAndFiles , liveSyncOptions ) ;
199- shouldRefreshApplication = platformLiveSyncService . afterInstallApplicationAction ( deviceAppData , localToDevicePaths ) . wait ( ) ;
200- } else {
201- shouldRefreshApplication = false ;
202- }
195+ let localToDevicePaths = this . $projectFilesManager . createLocalToDevicePaths ( deviceAppData , projectFilesPath , filesToSync , data . excludedProjectDirsAndFiles , liveSyncOptions ) ;
196+ shouldRefreshApplication = platformLiveSyncService . afterInstallApplicationAction ( deviceAppData , localToDevicePaths ) . wait ( ) ;
203197
204- if ( device . applicationManager . canStartApplication ( ) && ! shouldRefreshApplication ) {
205- device . applicationManager . startApplication ( appIdentifier ) . wait ( ) ;
206- }
207- wasInstalled = false ;
198+ if ( device . applicationManager . canStartApplication ( ) && ! shouldRefreshApplication ) {
199+ device . applicationManager . startApplication ( appIdentifier ) . wait ( ) ;
208200 }
201+ wasInstalled = false ;
202+ }
209203
210- // Restart application or reload page
211- if ( shouldRefreshApplication ) {
212- // Transfer or remove files on device
213- let localToDevicePaths = this . $projectFilesManager . createLocalToDevicePaths ( deviceAppData , projectFilesPath , filesToSync , data . excludedProjectDirsAndFiles , liveSyncOptions ) ;
214- if ( deviceFilesAction ) {
215- deviceFilesAction ( device , localToDevicePaths ) . wait ( ) ;
216- } else {
217- this . transferFiles ( deviceAppData , localToDevicePaths , projectFilesPath , ! filesToSync ) . wait ( ) ;
218- }
219-
220- this . $logger . info ( "Applying changes..." ) ;
221- platformLiveSyncService . refreshApplication ( deviceAppData , localToDevicePaths , data . forceExecuteFullSync || ! wasInstalled ) . wait ( ) ;
222- this . $logger . info ( `Successfully synced application ${ data . appIdentifier } on device ${ device . deviceInfo . identifier } .` ) ;
204+ // Restart application or reload page
205+ if ( shouldRefreshApplication ) {
206+ // Transfer or remove files on device
207+ let localToDevicePaths = this . $projectFilesManager . createLocalToDevicePaths ( deviceAppData , projectFilesPath , filesToSync , data . excludedProjectDirsAndFiles , liveSyncOptions ) ;
208+ if ( deviceFilesAction ) {
209+ deviceFilesAction ( device , localToDevicePaths ) . wait ( ) ;
210+ } else {
211+ this . transferFiles ( deviceAppData , localToDevicePaths , projectFilesPath , ! filesToSync ) . wait ( ) ;
223212 }
224- } else {
225- this . $logger . warn ( `LiveSync is not supported for application: ${ deviceAppData . appIdentifier } on device with identifier ${ device . deviceInfo . identifier } .` ) ;
213+
214+ this . $logger . info ( "Applying changes..." ) ;
215+ platformLiveSyncService . refreshApplication ( deviceAppData , localToDevicePaths , data . forceExecuteFullSync || ! wasInstalled ) . wait ( ) ;
216+ this . $logger . info ( `Successfully synced application ${ data . appIdentifier } on device ${ device . deviceInfo . identifier } .` ) ;
226217 }
227218 } ) . future < void > ( ) ( ) ;
228219 } ;
@@ -235,7 +226,7 @@ class LiveSyncServiceBase implements ILiveSyncServiceBase {
235226 for ( let dataItem of data ) {
236227 let appIdentifier = dataItem . appIdentifier ;
237228 let platform = dataItem . platform ;
238- let canExecute = this . getCanExecuteAction ( platform , appIdentifier , dataItem . canExecute ) ;
229+ let canExecute = this . getCanExecuteAction ( platform , appIdentifier ) ;
239230 let action = this . getSyncAction ( dataItem , filesToSync , deviceFilesAction , { isForCompanionApp : this . $options . companion , additionalConfigurations : dataItem . additionalConfigurations , configuration : dataItem . configuration , isForDeletedFiles : false } ) ;
240231 this . $devicesService . execute ( action , canExecute ) . wait ( ) ;
241232 }
@@ -275,16 +266,16 @@ class LiveSyncServiceBase implements ILiveSyncServiceBase {
275266 return this . $injector . resolve ( this . $liveSyncProvider . platformSpecificLiveSyncServices [ platform . toLowerCase ( ) ] , { _device : device } ) ;
276267 }
277268
278- public getCanExecuteAction ( platform : string , appIdentifier : string , canExecute : ( dev : Mobile . IDevice ) => boolean ) : ( dev : Mobile . IDevice ) => boolean {
279- canExecute = canExecute || ( ( dev : Mobile . IDevice ) => dev . deviceInfo . platform . toLowerCase ( ) === platform . toLowerCase ( ) ) ;
280- let finalCanExecute = canExecute ;
269+ public getCanExecuteAction ( platform : string , appIdentifier : string ) : ( dev : Mobile . IDevice ) => boolean {
270+ let isTheSamePlatformAction = ( ( device : Mobile . IDevice ) => device . deviceInfo . platform . toLowerCase ( ) === platform . toLowerCase ( ) ) ;
281271 if ( this . $options . device ) {
282- return ( device : Mobile . IDevice ) : boolean => canExecute ( device ) && device . deviceInfo . identifier === this . $devicesService . getDeviceByDeviceOption ( ) . deviceInfo . identifier ;
272+ return ( device : Mobile . IDevice ) : boolean => isTheSamePlatformAction ( device )
273+ && device . deviceInfo . identifier === this . $devicesService . getDeviceByDeviceOption ( ) . deviceInfo . identifier ;
283274 }
284275
285276 if ( this . $mobileHelper . isiOSPlatform ( platform ) ) {
286277 if ( this . $options . emulator ) {
287- finalCanExecute = ( device : Mobile . IDevice ) : boolean => canExecute ( device ) && this . $devicesService . isiOSSimulator ( device ) ;
278+ return ( device : Mobile . IDevice ) : boolean => isTheSamePlatformAction ( device ) && this . $devicesService . isiOSSimulator ( device ) ;
288279 } else {
289280 let devices = this . $devicesService . getDevicesForPlatform ( platform ) ;
290281 let simulator = _ . find ( devices , d => this . $devicesService . isiOSSimulator ( d ) ) ;
@@ -295,14 +286,14 @@ class LiveSyncServiceBase implements ILiveSyncServiceBase {
295286 let isApplicationInstalledOnAllDevices = _ . intersection . apply ( null , iOSDevices . map ( device => device . applicationManager . isApplicationInstalled ( appIdentifier ) . wait ( ) ) ) ;
296287 // In case the application is not installed on both device and simulator, syncs only on device.
297288 if ( ! isApplicationInstalledOnSimulator && ! isApplicationInstalledOnAllDevices ) {
298- finalCanExecute = ( device : Mobile . IDevice ) : boolean => canExecute ( device ) && this . $devicesService . isiOSDevice ( device ) ;
289+ return ( device : Mobile . IDevice ) : boolean => isTheSamePlatformAction ( device ) && this . $devicesService . isiOSDevice ( device ) ;
299290 }
300291 }
301292 }
302293 }
303294 }
304295
305- return finalCanExecute ;
296+ return isTheSamePlatformAction ;
306297 }
307298}
308299$injector . register ( 'liveSyncServiceBase' , LiveSyncServiceBase ) ;
0 commit comments