@@ -7,6 +7,7 @@ import { LiveSyncServiceResolver } from "../resolvers/livesync-service-resolver"
77import { RunOnDevicesDataService } from "../services/run-on-devices-data-service" ;
88import { RunOnDevicesEmitter } from "../run-on-devices-emitter" ;
99import { WorkflowDataService } from "../services/workflow/workflow-data-service" ;
10+ import { HmrConstants } from "../common/constants" ;
1011
1112export class RunOnDevicesController extends EventEmitter {
1213 constructor (
@@ -15,6 +16,7 @@ export class RunOnDevicesController extends EventEmitter {
1516 private $deviceInstallAppService : DeviceInstallAppService ,
1617 private $deviceRefreshAppService : DeviceRefreshAppService ,
1718 private $devicesService : Mobile . IDevicesService ,
19+ private $hmrStatusService : IHmrStatusService ,
1820 public $hooksService : IHooksService ,
1921 private $liveSyncServiceResolver : LiveSyncServiceResolver ,
2022 private $logger : ILogger ,
@@ -65,7 +67,7 @@ export class RunOnDevicesController extends EventEmitter {
6567 } ) ;
6668
6769 if ( liveSyncResultInfo && deviceDescriptor . debugggingEnabled ) {
68- await this . $deviceDebugAppService . refreshApplicationWithDebug ( projectData , deviceDescriptor , refreshInfo ) ;
70+ await this . $deviceDebugAppService . enableDebugging ( projectData , deviceDescriptor , refreshInfo ) ;
6971 }
7072
7173 this . $logger . info ( `Successfully synced application ${ liveSyncResultInfo . deviceAppData . appIdentifier } on device ${ liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } .` ) ;
@@ -89,28 +91,36 @@ export class RunOnDevicesController extends EventEmitter {
8991 await this . $buildPlatformService . buildPlatform ( nativePlatformData , projectData , buildPlatformData ) ;
9092 }
9193
94+ const isInHMRMode = liveSyncInfo . useHotModuleReload && data . hmrData && data . hmrData . hash ;
95+ if ( isInHMRMode ) {
96+ this . $hmrStatusService . watchHmrStatus ( device . deviceInfo . identifier , data . hmrData . hash ) ;
97+ }
98+
9299 const platformLiveSyncService = this . $liveSyncServiceResolver . resolveLiveSyncService ( device . deviceInfo . platform ) ;
93- const liveSyncResultInfo = await platformLiveSyncService . liveSyncWatchAction ( device , {
100+ const watchInfo = {
94101 liveSyncDeviceInfo : deviceDescriptor ,
95102 projectData,
96- filesToRemove : [ ] ,
103+ filesToRemove : < any > [ ] ,
97104 filesToSync : data . files ,
98105 isReinstalled : false ,
99- hmrData : null , // platformHmrData ,
106+ hmrData : data . hmrData ,
100107 useHotModuleReload : liveSyncInfo . useHotModuleReload ,
101108 force : liveSyncInfo . force ,
102109 connectTimeout : 1000
103- } ) ;
104-
105- const refreshInfo = await this . $deviceRefreshAppService . refreshApplicationWithoutDebug ( projectData , liveSyncResultInfo , deviceDescriptor ) ;
106-
107- this . $runOnDevicesEmitter . emitRunOnDeviceExecutedEvent ( projectData , liveSyncResultInfo . deviceAppData . device , {
108- syncedFiles : liveSyncResultInfo . modifiedFilesData . map ( m => m . getLocalPath ( ) ) ,
109- isFullSync : liveSyncResultInfo . isFullSync
110- } ) ;
111-
112- if ( liveSyncResultInfo && deviceDescriptor . debugggingEnabled ) {
113- await this . $deviceDebugAppService . refreshApplicationWithDebug ( projectData , deviceDescriptor , refreshInfo ) ;
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 ) ;
123+ }
114124 }
115125
116126 this . $logger . info ( `Successfully synced application ${ liveSyncResultInfo . deviceAppData . appIdentifier } on device ${ liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } .` ) ;
@@ -126,6 +136,19 @@ export class RunOnDevicesController extends EventEmitter {
126136 }
127137 }
128138
139+ private async refreshApplication ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo , deviceDescriptor : ILiveSyncDeviceInfo ) {
140+ const refreshInfo = await this . $deviceRefreshAppService . refreshApplicationWithoutDebug ( projectData , liveSyncResultInfo , deviceDescriptor ) ;
141+
142+ this . $runOnDevicesEmitter . emitRunOnDeviceExecutedEvent ( projectData , liveSyncResultInfo . deviceAppData . device , {
143+ syncedFiles : liveSyncResultInfo . modifiedFilesData . map ( m => m . getLocalPath ( ) ) ,
144+ isFullSync : liveSyncResultInfo . isFullSync
145+ } ) ;
146+
147+ if ( liveSyncResultInfo && deviceDescriptor . debugggingEnabled ) {
148+ await this . $deviceDebugAppService . enableDebugging ( projectData , deviceDescriptor , refreshInfo ) ;
149+ }
150+ }
151+
129152 private async addActionToChain < T > ( projectDir : string , action : ( ) => Promise < T > ) : Promise < T > {
130153 const liveSyncInfo = this . $runOnDevicesDataService . getData ( projectDir ) ;
131154 if ( liveSyncInfo ) {
0 commit comments