@@ -41,8 +41,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
4141 super ( ) ;
4242 }
4343
44- public async liveSync ( deviceDescriptors : ILiveSyncDeviceInfo [ ] ,
45- liveSyncData : ILiveSyncInfo ) : Promise < void > {
44+ public async liveSync ( deviceDescriptors : ILiveSyncDeviceInfo [ ] , liveSyncData : ILiveSyncInfo ) : Promise < void > {
4645 const projectData = this . $projectDataService . getProjectData ( liveSyncData . projectDir ) ;
4746 await this . $pluginsService . ensureAllDependenciesAreInstalled ( projectData ) ;
4847 await this . liveSyncOperation ( deviceDescriptors , liveSyncData , projectData ) ;
@@ -318,27 +317,19 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
318317 }
319318
320319 @hook ( "liveSync" )
321- private async liveSyncOperation ( deviceDescriptors : ILiveSyncDeviceInfo [ ] ,
322- liveSyncData : ILiveSyncInfo , projectData : IProjectData ) : Promise < void > {
320+ private async liveSyncOperation ( deviceDescriptors : ILiveSyncDeviceInfo [ ] , liveSyncData : ILiveSyncInfo , projectData : IProjectData ) : Promise < void > {
323321 // In case liveSync is called for a second time for the same projectDir.
324322 const isAlreadyLiveSyncing = this . liveSyncProcessesInfo [ projectData . projectDir ] && ! this . liveSyncProcessesInfo [ projectData . projectDir ] . isStopped ;
325323
326- // Prevent cases where liveSync is called consecutive times with the same device, for example [ A, B, C ] and then [ A, B, D ] - we want to execute initialSync only for D.
327- const currentlyRunningDeviceDescriptors = this . getLiveSyncDeviceDescriptors ( projectData . projectDir ) ;
328- const deviceDescriptorsForInitialSync = isAlreadyLiveSyncing ? _ . differenceBy ( deviceDescriptors , currentlyRunningDeviceDescriptors , deviceDescriptorPrimaryKey ) : deviceDescriptors ;
329324 this . setLiveSyncProcessInfo ( liveSyncData . projectDir , deviceDescriptors ) ;
330325
331- await this . initialSync ( projectData , deviceDescriptorsForInitialSync , liveSyncData ) ;
332-
333326 if ( ! liveSyncData . skipWatcher && this . liveSyncProcessesInfo [ projectData . projectDir ] . deviceDescriptors . length ) {
334327 // Should be set after prepare
335328 this . $usbLiveSyncService . isInitialized = true ;
336-
337- const devicesIds = deviceDescriptors . map ( dd => dd . identifier ) ;
338- const devices = _ . filter ( this . $devicesService . getDeviceInstances ( ) , device => _ . includes ( devicesIds , device . deviceInfo . identifier ) ) ;
339- const platforms = _ ( devices ) . map ( device => device . deviceInfo . platform ) . uniq ( ) . value ( ) ;
340- await this . startWatcher ( projectData , liveSyncData , platforms ) ;
329+ await this . startWatcher ( projectData , liveSyncData , deviceDescriptors , { isAlreadyLiveSyncing } ) ;
341330 }
331+
332+ await this . initialSync ( projectData , liveSyncData , deviceDescriptors , { isAlreadyLiveSyncing } ) ;
342333 }
343334
344335 private setLiveSyncProcessInfo ( projectDir : string , deviceDescriptors : ILiveSyncDeviceInfo [ ] ) : void {
@@ -351,6 +342,13 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
351342 this . liveSyncProcessesInfo [ projectDir ] . deviceDescriptors = _ . uniqBy ( currentDeviceDescriptors . concat ( deviceDescriptors ) , deviceDescriptorPrimaryKey ) ;
352343 }
353344
345+ private async initialSync ( projectData : IProjectData , liveSyncData : ILiveSyncInfo , deviceDescriptors : ILiveSyncDeviceInfo [ ] , options : { isAlreadyLiveSyncing : boolean } ) : Promise < void > {
346+ // Prevent cases where liveSync is called consecutive times with the same device, for example [ A, B, C ] and then [ A, B, D ] - we want to execute initialSync only for D.
347+ const currentlyRunningDeviceDescriptors = this . getLiveSyncDeviceDescriptors ( projectData . projectDir ) ;
348+ const deviceDescriptorsForInitialSync = options . isAlreadyLiveSyncing ? _ . differenceBy ( deviceDescriptors , currentlyRunningDeviceDescriptors , deviceDescriptorPrimaryKey ) : deviceDescriptors ;
349+ await this . initialSyncCore ( projectData , deviceDescriptorsForInitialSync , liveSyncData ) ;
350+ }
351+
354352 private getLiveSyncService ( platform : string ) : IPlatformLiveSyncService {
355353 if ( this . $mobileHelper . isiOSPlatform ( platform ) ) {
356354 return this . $injector . resolve ( "iOSLiveSyncService" ) ;
@@ -452,7 +450,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
452450 return null ;
453451 }
454452
455- private async initialSync ( projectData : IProjectData , deviceDescriptors : ILiveSyncDeviceInfo [ ] , liveSyncData : ILiveSyncInfo ) : Promise < void > {
453+ private async initialSyncCore ( projectData : IProjectData , deviceDescriptors : ILiveSyncDeviceInfo [ ] , liveSyncData : ILiveSyncInfo ) : Promise < void > {
456454 const preparedPlatforms : string [ ] = [ ] ;
457455 const rebuiltInformation : ILiveSyncBuildInfo [ ] = [ ] ;
458456
@@ -483,6 +481,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
483481 useLiveEdit : liveSyncData . useLiveEdit ,
484482 watch : ! liveSyncData . skipWatcher
485483 } ) ;
484+
486485 await this . $platformService . trackActionForPlatform ( { action : "LiveSync" , platform : device . deviceInfo . platform , isForDevice : ! device . isEmulator , deviceOsVersion : device . deviceInfo . version } ) ;
487486 await this . refreshApplication ( projectData , liveSyncResultInfo , deviceBuildInfoDescriptor . debugOptions , deviceBuildInfoDescriptor . outputPath ) ;
488487
@@ -525,7 +524,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
525524 } ;
526525 }
527526
528- private async startWatcher ( projectData : IProjectData , liveSyncData : ILiveSyncInfo , platforms : string [ ] ) : Promise < void > {
527+ private async startWatcher ( projectData : IProjectData , liveSyncData : ILiveSyncInfo , deviceDescriptors : ILiveSyncDeviceInfo [ ] , options : { isAlreadyLiveSyncing : boolean } ) : Promise < void > {
528+ const devicesIds = deviceDescriptors . map ( dd => dd . identifier ) ;
529+ const devices = _ . filter ( this . $devicesService . getDeviceInstances ( ) , device => _ . includes ( devicesIds , device . deviceInfo . identifier ) ) ;
530+ const platforms = _ ( devices ) . map ( device => device . deviceInfo . platform ) . uniq ( ) . value ( ) ;
529531 const patterns = await this . getWatcherPatterns ( liveSyncData , projectData , platforms ) ;
530532
531533 if ( liveSyncData . watchAllFiles ) {
0 commit comments