@@ -318,26 +318,16 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
318
318
}
319
319
320
320
@hook ( "liveSync" )
321
- private async liveSyncOperation ( deviceDescriptors : ILiveSyncDeviceInfo [ ] ,
322
- liveSyncData : ILiveSyncInfo , projectData : IProjectData ) : Promise < void > {
321
+ private async liveSyncOperation ( deviceDescriptors : ILiveSyncDeviceInfo [ ] , liveSyncData : ILiveSyncInfo , projectData : IProjectData ) : Promise < void > {
323
322
// In case liveSync is called for a second time for the same projectDir.
324
323
const isAlreadyLiveSyncing = this . liveSyncProcessesInfo [ projectData . projectDir ] && ! this . liveSyncProcessesInfo [ projectData . projectDir ] . isStopped ;
325
324
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 ;
329
325
this . setLiveSyncProcessInfo ( liveSyncData . projectDir , deviceDescriptors ) ;
330
326
331
- await this . initialSync ( projectData , deviceDescriptorsForInitialSync , liveSyncData ) ;
332
-
333
327
if ( ! liveSyncData . skipWatcher && this . liveSyncProcessesInfo [ projectData . projectDir ] . deviceDescriptors . length ) {
334
328
// Should be set after prepare
335
329
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 ) ;
330
+ await this . startWatcher ( projectData , liveSyncData , deviceDescriptors , { isAlreadyLiveSyncing } ) ;
341
331
}
342
332
}
343
333
@@ -351,6 +341,13 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
351
341
this . liveSyncProcessesInfo [ projectDir ] . deviceDescriptors = _ . uniqBy ( currentDeviceDescriptors . concat ( deviceDescriptors ) , deviceDescriptorPrimaryKey ) ;
352
342
}
353
343
344
+ private async initialSync ( projectData : IProjectData , liveSyncData : ILiveSyncInfo , deviceDescriptors : ILiveSyncDeviceInfo [ ] , options : { isAlreadyLiveSyncing : boolean } ) : Promise < void > {
345
+ // 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.
346
+ const currentlyRunningDeviceDescriptors = this . getLiveSyncDeviceDescriptors ( projectData . projectDir ) ;
347
+ const deviceDescriptorsForInitialSync = options . isAlreadyLiveSyncing ? _ . differenceBy ( deviceDescriptors , currentlyRunningDeviceDescriptors , deviceDescriptorPrimaryKey ) : deviceDescriptors ;
348
+ await this . initialSyncCore ( projectData , deviceDescriptorsForInitialSync , liveSyncData ) ;
349
+ }
350
+
354
351
private getLiveSyncService ( platform : string ) : IPlatformLiveSyncService {
355
352
if ( this . $mobileHelper . isiOSPlatform ( platform ) ) {
356
353
return this . $injector . resolve ( "iOSLiveSyncService" ) ;
@@ -452,7 +449,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
452
449
return null ;
453
450
}
454
451
455
- private async initialSync ( projectData : IProjectData , deviceDescriptors : ILiveSyncDeviceInfo [ ] , liveSyncData : ILiveSyncInfo ) : Promise < void > {
452
+ private async initialSyncCore ( projectData : IProjectData , deviceDescriptors : ILiveSyncDeviceInfo [ ] , liveSyncData : ILiveSyncInfo ) : Promise < void > {
456
453
const preparedPlatforms : string [ ] = [ ] ;
457
454
const rebuiltInformation : ILiveSyncBuildInfo [ ] = [ ] ;
458
455
@@ -483,6 +480,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
483
480
useLiveEdit : liveSyncData . useLiveEdit ,
484
481
watch : ! liveSyncData . skipWatcher
485
482
} ) ;
483
+
486
484
await this . $platformService . trackActionForPlatform ( { action : "LiveSync" , platform : device . deviceInfo . platform , isForDevice : ! device . isEmulator , deviceOsVersion : device . deviceInfo . version } ) ;
487
485
await this . refreshApplication ( projectData , liveSyncResultInfo , deviceBuildInfoDescriptor . debugOptions , deviceBuildInfoDescriptor . outputPath ) ;
488
486
@@ -525,7 +523,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
525
523
} ;
526
524
}
527
525
528
- private async startWatcher ( projectData : IProjectData , liveSyncData : ILiveSyncInfo , platforms : string [ ] ) : Promise < void > {
526
+ private async startWatcher ( projectData : IProjectData , liveSyncData : ILiveSyncInfo , deviceDescriptors : ILiveSyncDeviceInfo [ ] , options : { isAlreadyLiveSyncing : boolean } ) : Promise < void > {
527
+ const devicesIds = deviceDescriptors . map ( dd => dd . identifier ) ;
528
+ const devices = _ . filter ( this . $devicesService . getDeviceInstances ( ) , device => _ . includes ( devicesIds , device . deviceInfo . identifier ) ) ;
529
+ const platforms = _ ( devices ) . map ( device => device . deviceInfo . platform ) . uniq ( ) . value ( ) ;
529
530
const patterns = await this . getWatcherPatterns ( liveSyncData , projectData , platforms ) ;
530
531
531
532
if ( liveSyncData . watchAllFiles ) {
@@ -683,6 +684,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
683
684
this . liveSyncProcessesInfo [ liveSyncData . projectDir ] . watcherInfo = { watcher, patterns } ;
684
685
this . liveSyncProcessesInfo [ liveSyncData . projectDir ] . timer = timeoutTimer ;
685
686
687
+ await this . initialSync ( projectData , liveSyncData , deviceDescriptors , options ) ;
688
+
686
689
this . $processService . attachToProcessExitSignals ( this , ( ) => {
687
690
_ . keys ( this . liveSyncProcessesInfo ) . forEach ( projectDir => {
688
691
// Do not await here, we are in process exit's handler.
0 commit comments