@@ -41,8 +41,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
41
41
super ( ) ;
42
42
}
43
43
44
- public async liveSync ( deviceDescriptors : ILiveSyncDeviceInfo [ ] ,
45
- liveSyncData : ILiveSyncInfo ) : Promise < void > {
44
+ public async liveSync ( deviceDescriptors : ILiveSyncDeviceInfo [ ] , liveSyncData : ILiveSyncInfo ) : Promise < void > {
46
45
const projectData = this . $projectDataService . getProjectData ( liveSyncData . projectDir ) ;
47
46
await this . $pluginsService . ensureAllDependenciesAreInstalled ( projectData ) ;
48
47
await this . liveSyncOperation ( deviceDescriptors , liveSyncData , projectData ) ;
@@ -318,27 +317,19 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
318
317
}
319
318
320
319
@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 > {
323
321
// In case liveSync is called for a second time for the same projectDir.
324
322
const isAlreadyLiveSyncing = this . liveSyncProcessesInfo [ projectData . projectDir ] && ! this . liveSyncProcessesInfo [ projectData . projectDir ] . isStopped ;
325
323
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
324
this . setLiveSyncProcessInfo ( liveSyncData . projectDir , deviceDescriptors ) ;
330
325
331
- await this . initialSync ( projectData , deviceDescriptorsForInitialSync , liveSyncData ) ;
332
-
333
326
if ( ! liveSyncData . skipWatcher && this . liveSyncProcessesInfo [ projectData . projectDir ] . deviceDescriptors . length ) {
334
327
// Should be set after prepare
335
328
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 } ) ;
341
330
}
331
+
332
+ await this . initialSync ( projectData , liveSyncData , deviceDescriptors , { isAlreadyLiveSyncing } ) ;
342
333
}
343
334
344
335
private setLiveSyncProcessInfo ( projectDir : string , deviceDescriptors : ILiveSyncDeviceInfo [ ] ) : void {
@@ -351,6 +342,13 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
351
342
this . liveSyncProcessesInfo [ projectDir ] . deviceDescriptors = _ . uniqBy ( currentDeviceDescriptors . concat ( deviceDescriptors ) , deviceDescriptorPrimaryKey ) ;
352
343
}
353
344
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
+
354
352
private getLiveSyncService ( platform : string ) : IPlatformLiveSyncService {
355
353
if ( this . $mobileHelper . isiOSPlatform ( platform ) ) {
356
354
return this . $injector . resolve ( "iOSLiveSyncService" ) ;
@@ -452,7 +450,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
452
450
return null ;
453
451
}
454
452
455
- private async initialSync ( projectData : IProjectData , deviceDescriptors : ILiveSyncDeviceInfo [ ] , liveSyncData : ILiveSyncInfo ) : Promise < void > {
453
+ private async initialSyncCore ( projectData : IProjectData , deviceDescriptors : ILiveSyncDeviceInfo [ ] , liveSyncData : ILiveSyncInfo ) : Promise < void > {
456
454
const preparedPlatforms : string [ ] = [ ] ;
457
455
const rebuiltInformation : ILiveSyncBuildInfo [ ] = [ ] ;
458
456
@@ -483,6 +481,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
483
481
useLiveEdit : liveSyncData . useLiveEdit ,
484
482
watch : ! liveSyncData . skipWatcher
485
483
} ) ;
484
+
486
485
await this . $platformService . trackActionForPlatform ( { action : "LiveSync" , platform : device . deviceInfo . platform , isForDevice : ! device . isEmulator , deviceOsVersion : device . deviceInfo . version } ) ;
487
486
await this . refreshApplication ( projectData , liveSyncResultInfo , deviceBuildInfoDescriptor . debugOptions , deviceBuildInfoDescriptor . outputPath ) ;
488
487
@@ -525,7 +524,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
525
524
} ;
526
525
}
527
526
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 ( ) ;
529
531
const patterns = await this . getWatcherPatterns ( liveSyncData , projectData , platforms ) ;
530
532
531
533
if ( liveSyncData . watchAllFiles ) {
0 commit comments