Skip to content

fix: recover android application if with hmr and in ErrorActivity #4017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/definitions/livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,15 @@ interface ILiveSyncWatchInfo extends IProjectDataComposition, IHasUseHotModuleRe
isReinstalled: boolean;
syncAllFiles: boolean;
liveSyncDeviceInfo: ILiveSyncDeviceInfo;
hmrData: { hash: string; fallbackFiles: IDictionary<string[]> };
force?: boolean;
}

interface ILiveSyncResultInfo extends IHasUseHotModuleReloadOption {
modifiedFilesData: Mobile.ILocalToDevicePathData[];
isFullSync: boolean;
deviceAppData: Mobile.IDeviceAppData;
didRecover?: boolean
}

interface IAndroidLiveSyncResultInfo extends ILiveSyncResultInfo, IAndroidLivesyncSyncOperationResult { }
Expand Down
16 changes: 16 additions & 0 deletions lib/services/livesync/android-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,24 @@ export class AndroidLiveSyncService extends PlatformLiveSyncServiceBase implemen
}

public async liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<IAndroidLiveSyncResultInfo> {
let result = await this.liveSyncWatchActionCore(device, liveSyncInfo);

// When we use hmr, there is only one case when result.didRefresh is false.
// This is the case when the app has crashed and is in ErrorActivity.
// As the app might not have time to apply the patches, we will send the whole bundle.js(fallbackFiles)
if (liveSyncInfo.useHotModuleReload && !result.didRefresh && liveSyncInfo.hmrData && liveSyncInfo.hmrData.hash) {
liveSyncInfo.filesToSync = liveSyncInfo.hmrData.fallbackFiles[device.deviceInfo.platform];
result = await this.liveSyncWatchActionCore(device, liveSyncInfo);
result.didRecover = true;
}

return result;
}

private async liveSyncWatchActionCore(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<IAndroidLiveSyncResultInfo> {
const liveSyncResult = await super.liveSyncWatchAction(device, liveSyncInfo);
const result = await this.finalizeSync(device, liveSyncInfo.projectData, liveSyncResult);

return result;
}

Expand Down
5 changes: 4 additions & 1 deletion lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
filesToSync: currentFilesToSync,
isReinstalled: appInstalledOnDeviceResult.appInstalled,
syncAllFiles: liveSyncData.watchAllFiles,
hmrData: currentHmrData,
useHotModuleReload: liveSyncData.useHotModuleReload,
force: liveSyncData.force
};
Expand All @@ -674,11 +675,13 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi

await this.refreshApplication(projectData, liveSyncResultInfo, deviceBuildInfoDescriptor.debugOptions, deviceBuildInfoDescriptor.outputPath);

if (liveSyncData.useHotModuleReload && currentHmrData.hash) {
//If didRecover is true, this means we were in ErrorActivity and fallback files were already transfered and app will be restarted.
if (!liveSyncResultInfo.didRecover && liveSyncData.useHotModuleReload && currentHmrData.hash) {
const status = await this.$hmrStatusService.getHmrStatus(device.deviceInfo.identifier, currentHmrData.hash);
if (status === HmrConstants.HMR_ERROR_STATUS) {
settings.filesToSync = currentHmrData.fallbackFiles[device.deviceInfo.platform];
liveSyncResultInfo = await service.liveSyncWatchAction(device, settings);
//We want to force a restart of the application.
liveSyncResultInfo.isFullSync = true;
await this.refreshApplication(projectData, liveSyncResultInfo, deviceBuildInfoDescriptor.debugOptions, deviceBuildInfoDescriptor.outputPath);
}
Expand Down