@@ -26,114 +26,106 @@ export class RunOnDevicesController extends EventEmitter {
2626 ) { super ( ) ; }
2727
2828 public async syncInitialDataOnDevice ( data : IInitialSyncEventData , projectData : IProjectData , liveSyncInfo : ILiveSyncInfo , deviceDescriptors : ILiveSyncDeviceInfo [ ] ) : Promise < void > {
29- const executeAction = async ( device : Mobile . IDevice ) => {
29+ const deviceAction = async ( device : Mobile . IDevice ) => {
3030 const deviceDescriptor = _ . find ( deviceDescriptors , dd => dd . identifier === device . deviceInfo . identifier ) ;
31- await this . syncInitialDataOnDeviceSafe ( device , deviceDescriptor , projectData , liveSyncInfo ) ;
32- } ;
33- const canExecuteAction = ( device : Mobile . IDevice ) => device . deviceInfo . platform . toLowerCase ( ) === data . platform . toLowerCase ( ) && _ . some ( deviceDescriptors , deviceDescriptor => deviceDescriptor . identifier === device . deviceInfo . identifier ) ;
34- await this . addActionToChain ( projectData . projectDir , ( ) => this . $devicesService . execute ( executeAction , canExecuteAction ) ) ;
35- }
36-
37- public async syncChangedDataOnDevice ( data : IFilesChangeEventData , projectData : IProjectData , liveSyncInfo : ILiveSyncInfo , deviceDescriptors : ILiveSyncDeviceInfo [ ] ) : Promise < void > {
38- const executeAction = async ( device : Mobile . IDevice ) => {
39- const deviceDescriptor = _ . find ( deviceDescriptors , dd => dd . identifier === device . deviceInfo . identifier ) ;
40- await this . syncChangedDataOnDeviceSafe ( device , deviceDescriptor , data , projectData , liveSyncInfo ) ;
41- } ;
42- const canExecuteAction = ( device : Mobile . IDevice ) => {
43- const liveSyncProcessInfo = this . $runOnDevicesDataService . getData ( projectData . projectDir ) ;
44- return ( data . platform . toLowerCase ( ) === device . deviceInfo . platform . toLowerCase ( ) ) && liveSyncProcessInfo && _ . some ( liveSyncProcessInfo . deviceDescriptors , deviceDescriptor => deviceDescriptor . identifier === device . deviceInfo . identifier ) ;
45- } ;
46- await this . addActionToChain ( projectData . projectDir , ( ) => this . $devicesService . execute ( executeAction , canExecuteAction ) ) ;
47- }
31+ const { nativePlatformData : platformData , buildPlatformData } = this . $workflowDataService . createWorkflowData ( device . deviceInfo . platform , projectData . projectDir , liveSyncInfo ) ;
4832
49- private async syncInitialDataOnDeviceSafe ( device : Mobile . IDevice , deviceDescriptor : ILiveSyncDeviceInfo , projectData : IProjectData , liveSyncInfo : ILiveSyncInfo ) : Promise < void > {
50- const { nativePlatformData : platformData , buildPlatformData } = this . $workflowDataService . createWorkflowData ( device . deviceInfo . platform , projectData . projectDir , liveSyncInfo ) ;
33+ try {
34+ const outputPath = deviceDescriptor . outputPath || platformData . getBuildOutputPath ( buildPlatformData ) ;
35+ const packageFilePath = await this . $buildPlatformService . buildPlatformIfNeeded ( platformData , projectData , buildPlatformData , outputPath ) ;
5136
52- try {
53- const outputPath = deviceDescriptor . outputPath || platformData . getBuildOutputPath ( buildPlatformData ) ;
54- const packageFilePath = await this . $buildPlatformService . buildPlatformIfNeeded ( platformData , projectData , buildPlatformData , outputPath ) ;
37+ await this . $deviceInstallAppService . installOnDeviceIfNeeded ( device , platformData , projectData , buildPlatformData , packageFilePath , outputPath ) ;
5538
56- await this . $deviceInstallAppService . installOnDeviceIfNeeded ( device , platformData , projectData , buildPlatformData , packageFilePath , outputPath ) ;
39+ const platformLiveSyncService = this . $liveSyncServiceResolver . resolveLiveSyncService ( platformData . platformNameLowerCase ) ;
40+ const { force, useHotModuleReload, skipWatcher } = liveSyncInfo ;
41+ const liveSyncResultInfo = await platformLiveSyncService . fullSync ( { force, useHotModuleReload, projectData, device, watch : ! skipWatcher , liveSyncDeviceInfo : deviceDescriptor } ) ;
5742
58- const platformLiveSyncService = this . $liveSyncServiceResolver . resolveLiveSyncService ( platformData . platformNameLowerCase ) ;
59- const { force, useHotModuleReload, skipWatcher } = liveSyncInfo ;
60- const liveSyncResultInfo = await platformLiveSyncService . fullSync ( { force, useHotModuleReload, projectData, device, watch : ! skipWatcher , liveSyncDeviceInfo : deviceDescriptor } ) ;
43+ const refreshInfo = await this . $deviceRefreshAppService . refreshApplicationWithoutDebug ( projectData , liveSyncResultInfo , deviceDescriptor ) ;
6144
62- const refreshInfo = await this . $deviceRefreshAppService . refreshApplicationWithoutDebug ( projectData , liveSyncResultInfo , deviceDescriptor ) ;
45+ this . $runOnDevicesEmitter . emitRunOnDeviceExecutedEvent ( projectData , liveSyncResultInfo . deviceAppData . device , {
46+ syncedFiles : liveSyncResultInfo . modifiedFilesData . map ( m => m . getLocalPath ( ) ) ,
47+ isFullSync : liveSyncResultInfo . isFullSync
48+ } ) ;
6349
64- this . $runOnDevicesEmitter . emitRunOnDeviceExecutedEvent ( projectData , liveSyncResultInfo . deviceAppData . device , {
65- syncedFiles : liveSyncResultInfo . modifiedFilesData . map ( m => m . getLocalPath ( ) ) ,
66- isFullSync : liveSyncResultInfo . isFullSync
67- } ) ;
50+ if ( liveSyncResultInfo && deviceDescriptor . debugggingEnabled ) {
51+ await this . $deviceDebugAppService . enableDebugging ( projectData , deviceDescriptor , refreshInfo ) ;
52+ }
6853
69- if ( liveSyncResultInfo && deviceDescriptor . debugggingEnabled ) {
70- await this . $deviceDebugAppService . enableDebugging ( projectData , deviceDescriptor , refreshInfo ) ;
71- }
54+ this . $logger . info ( `Successfully synced application ${ liveSyncResultInfo . deviceAppData . appIdentifier } on device ${ liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } .` ) ;
7255
73- this . $logger . info ( `Successfully synced application ${ liveSyncResultInfo . deviceAppData . appIdentifier } on device ${ liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } .` ) ;
56+ this . $runOnDevicesEmitter . emitRunOnDeviceStartedEvent ( projectData , device ) ;
57+ } catch ( err ) {
58+ this . $logger . warn ( `Unable to apply changes on device: ${ device . deviceInfo . identifier } . Error is: ${ err . message } .` ) ;
7459
75- this . $runOnDevicesEmitter . emitRunOnDeviceStartedEvent ( projectData , device ) ;
76- } catch ( err ) {
77- this . $logger . warn ( `Unable to apply changes on device: ${ device . deviceInfo . identifier } . Error is: ${ err . message } .` ) ;
60+ this . $runOnDevicesEmitter . emitRunOnDeviceErrorEvent ( projectData , device , err ) ;
7861
79- this . $runOnDevicesEmitter . emitRunOnDeviceErrorEvent ( projectData , device , err ) ;
62+ // TODO: Consider to call here directly stopRunOnDevices
63+ }
64+ } ;
8065
81- // TODO: Consider to call here directly stopRunOnDevices
82- }
66+ await this . addActionToChain ( projectData . projectDir , ( ) => this . $devicesService . execute ( deviceAction , ( device : Mobile . IDevice ) => device . deviceInfo . platform . toLowerCase ( ) === data . platform . toLowerCase ( ) && _ . some ( deviceDescriptors , deviceDescriptor => deviceDescriptor . identifier === device . deviceInfo . identifier ) ) ) ;
8367 }
8468
85- private async syncChangedDataOnDeviceSafe ( device : Mobile . IDevice , deviceDescriptor : ILiveSyncDeviceInfo , data : IFilesChangeEventData , projectData : IProjectData , liveSyncInfo : ILiveSyncInfo ) : Promise < void > {
86- const { nativePlatformData, buildPlatformData } = this . $workflowDataService . createWorkflowData ( device . deviceInfo . platform , projectData . projectDir , liveSyncInfo ) ;
69+ public async syncChangedDataOnDevice ( data : IFilesChangeEventData , projectData : IProjectData , liveSyncInfo : ILiveSyncInfo , deviceDescriptors : ILiveSyncDeviceInfo [ ] ) : Promise < void > {
70+ const deviceAction = async ( device : Mobile . IDevice ) => {
71+ const deviceDescriptor = _ . find ( deviceDescriptors , dd => dd . identifier === device . deviceInfo . identifier ) ;
72+ const { nativePlatformData, buildPlatformData } = this . $workflowDataService . createWorkflowData ( device . deviceInfo . platform , projectData . projectDir , liveSyncInfo ) ;
8773
88- try {
89- if ( data . hasNativeChanges ) {
90- // TODO: Consider to handle nativePluginsChange here (aar rebuilt)
91- await this . $buildPlatformService . buildPlatform ( nativePlatformData , projectData , buildPlatformData ) ;
92- }
74+ try {
75+ if ( data . hasNativeChanges ) {
76+ // TODO: Consider to handle nativePluginsChange here (aar rebuilt)
77+ await this . $buildPlatformService . buildPlatform ( nativePlatformData , projectData , buildPlatformData ) ;
78+ }
9379
94- const isInHMRMode = liveSyncInfo . useHotModuleReload && data . hmrData && data . hmrData . hash ;
95- if ( isInHMRMode ) {
96- this . $hmrStatusService . watchHmrStatus ( device . deviceInfo . identifier , data . hmrData . hash ) ;
97- }
80+ const isInHMRMode = liveSyncInfo . useHotModuleReload && data . hmrData && data . hmrData . hash ;
81+ if ( isInHMRMode ) {
82+ this . $hmrStatusService . watchHmrStatus ( device . deviceInfo . identifier , data . hmrData . hash ) ;
83+ }
9884
99- const platformLiveSyncService = this . $liveSyncServiceResolver . resolveLiveSyncService ( device . deviceInfo . platform ) ;
100- const watchInfo = {
101- liveSyncDeviceInfo : deviceDescriptor ,
102- projectData,
103- filesToRemove : < any > [ ] ,
104- filesToSync : data . files ,
105- isReinstalled : false ,
106- hmrData : data . hmrData ,
107- useHotModuleReload : liveSyncInfo . useHotModuleReload ,
108- force : liveSyncInfo . force ,
109- connectTimeout : 1000
110- } ;
111- let liveSyncResultInfo = await platformLiveSyncService . liveSyncWatchAction ( device , watchInfo ) ;
112-
113- await this . refreshApplication ( projectData , liveSyncResultInfo , deviceDescriptor ) ;
114-
115- if ( ! liveSyncResultInfo . didRecover && isInHMRMode ) {
116- const status = await this . $hmrStatusService . getHmrStatus ( device . deviceInfo . identifier , data . hmrData . hash ) ;
117- if ( status === HmrConstants . HMR_ERROR_STATUS ) {
118- watchInfo . filesToSync = data . hmrData . fallbackFiles ;
119- liveSyncResultInfo = await platformLiveSyncService . liveSyncWatchAction ( device , watchInfo ) ;
120- // We want to force a restart of the application.
121- liveSyncResultInfo . isFullSync = true ;
122- await this . refreshApplication ( projectData , liveSyncResultInfo , deviceDescriptor ) ;
85+ const platformLiveSyncService = this . $liveSyncServiceResolver . resolveLiveSyncService ( device . deviceInfo . platform ) ;
86+ const watchInfo = {
87+ liveSyncDeviceInfo : deviceDescriptor ,
88+ projectData,
89+ filesToRemove : < any > [ ] ,
90+ filesToSync : data . files ,
91+ isReinstalled : false ,
92+ hmrData : data . hmrData ,
93+ useHotModuleReload : liveSyncInfo . useHotModuleReload ,
94+ force : liveSyncInfo . force ,
95+ connectTimeout : 1000
96+ } ;
97+ let liveSyncResultInfo = await platformLiveSyncService . liveSyncWatchAction ( device , watchInfo ) ;
98+
99+ await this . refreshApplication ( projectData , liveSyncResultInfo , deviceDescriptor ) ;
100+
101+ if ( ! liveSyncResultInfo . didRecover && isInHMRMode ) {
102+ const status = await this . $hmrStatusService . getHmrStatus ( device . deviceInfo . identifier , data . hmrData . hash ) ;
103+ if ( status === HmrConstants . HMR_ERROR_STATUS ) {
104+ watchInfo . filesToSync = data . hmrData . fallbackFiles ;
105+ liveSyncResultInfo = await platformLiveSyncService . liveSyncWatchAction ( device , watchInfo ) ;
106+ // We want to force a restart of the application.
107+ liveSyncResultInfo . isFullSync = true ;
108+ await this . refreshApplication ( projectData , liveSyncResultInfo , deviceDescriptor ) ;
109+ }
123110 }
124- }
125111
126- this . $logger . info ( `Successfully synced application ${ liveSyncResultInfo . deviceAppData . appIdentifier } on device ${ liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } .` ) ;
127- } catch ( err ) {
128- const allErrors = ( < Mobile . IDevicesOperationError > err ) . allErrors ;
112+ this . $logger . info ( `Successfully synced application ${ liveSyncResultInfo . deviceAppData . appIdentifier } on device ${ liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } .` ) ;
113+ } catch ( err ) {
114+ const allErrors = ( < Mobile . IDevicesOperationError > err ) . allErrors ;
129115
130- if ( allErrors && _ . isArray ( allErrors ) ) {
131- for ( const deviceError of allErrors ) {
132- this . $logger . warn ( `Unable to apply changes for device: ${ deviceError . deviceIdentifier } . Error is: ${ deviceError . message } .` ) ;
133- this . $runOnDevicesEmitter . emitRunOnDeviceErrorEvent ( projectData , device , deviceError ) ;
116+ if ( allErrors && _ . isArray ( allErrors ) ) {
117+ for ( const deviceError of allErrors ) {
118+ this . $logger . warn ( `Unable to apply changes for device: ${ deviceError . deviceIdentifier } . Error is: ${ deviceError . message } .` ) ;
119+ this . $runOnDevicesEmitter . emitRunOnDeviceErrorEvent ( projectData , device , deviceError ) ;
120+ }
134121 }
135122 }
136- }
123+ } ;
124+
125+ await this . addActionToChain ( projectData . projectDir , ( ) => this . $devicesService . execute ( deviceAction , ( device : Mobile . IDevice ) => {
126+ const liveSyncProcessInfo = this . $runOnDevicesDataService . getData ( projectData . projectDir ) ;
127+ return ( data . platform . toLowerCase ( ) === device . deviceInfo . platform . toLowerCase ( ) ) && liveSyncProcessInfo && _ . some ( liveSyncProcessInfo . deviceDescriptors , deviceDescriptor => deviceDescriptor . identifier === device . deviceInfo . identifier ) ;
128+ } ) ) ;
137129 }
138130
139131 private async refreshApplication ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo , deviceDescriptor : ILiveSyncDeviceInfo ) {
0 commit comments