diff --git a/CodePush.js b/CodePush.js index f98fc3999..deb1d856e 100644 --- a/CodePush.js +++ b/CodePush.js @@ -562,10 +562,10 @@ if (NativeCodePush) { allowRestart: NativeCodePush.allow, clearUpdates: NativeCodePush.clearUpdates, InstallMode: { - IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately - ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart - ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume, // Restart the app the next time it is resumed from the background - ON_NEXT_SUSPEND: NativeCodePush.codePushInstallModeOnNextSuspend // Restart the app _while_ it is in the background, + IMMEDIATE: 0, // Restart the app immediately + ON_NEXT_RESTART: 1, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart + ON_NEXT_RESUME: 2, // Restart the app the next time it is resumed from the background + ON_NEXT_SUSPEND: 3 // Restart the app _while_ it is in the background, // but only after it has been in the background for "minimumBackgroundDuration" seconds (0 by default), // so that user context isn't lost unless the app suspension is long enough to not matter }, diff --git a/harmony/codePush/src/main/ets/CodePushNativeModule.ts b/harmony/codePush/src/main/ets/CodePushNativeModule.ts index 7fab35862..bb1f980a4 100644 --- a/harmony/codePush/src/main/ets/CodePushNativeModule.ts +++ b/harmony/codePush/src/main/ets/CodePushNativeModule.ts @@ -6,7 +6,7 @@ import { CodePushUpdateManager } from './CodePushUpdateManager'; import { CodePushTelemetryManager } from './CodePushTelemetryManager'; import { CodePush } from './CodePush'; import common from '@ohos.app.ability.common'; -import fs from '@ohos.file.fs'; +import fs, { ListFileOptions } from '@ohos.file.fs'; import FileUtils from './FileUtils'; import { SettingsManager } from './SettingsManager'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -48,8 +48,8 @@ export class CodePushNativeModule extends TurboModule implements TM.RTNCodePush. private preferences: dataPreferences.Preferences | null = null; private mTelemetryManager: CodePushTelemetryManager | null = null; private mSettingsManager: SettingsManager | null = null; - private mUpdateManager: CodePushUpdateManager | null = null - + private mUpdateManager: CodePushUpdateManager | null = null; + installMode = 0; sync(): Promise { throw new Error('Method not implemented.'); @@ -247,6 +247,7 @@ export class CodePushNativeModule extends TurboModule implements TM.RTNCodePush. minimumBackgroundDuration: number): Promise { try { + this.installMode = installMode Logger.info(TAG, 'installPackage--CodePushNativeModule-entry') new CodePushUpdateManager('').installPackage(updatePackage, new SettingsManager().isPendingUpdate(null)) Logger.info(TAG, 'installPackage--CodePushNativeModule-end') @@ -381,18 +382,25 @@ export class CodePushNativeModule extends TurboModule implements TM.RTNCodePush. Logger.info(TAG, "restartAppInternal--loadBundle-start"); let info = new CodePushUpdateManager('').getCurrentPackageInfo(); let currentPackageHash: string = info[CodePushConstants.CURRENT_PACKAGE_KEY]; - let sx_latestJSBundleFile_assets = context.filesDir + '/CodePush/' + currentPackageHash + '/rawfile/assets'; - let sx_latestJSBundleFile_bundle = context.filesDir + '/CodePush/' + currentPackageHash + '/rawfile/bundle.harmony.js'; + const sx_latestJSBundleFile = context.filesDir + '/CodePush/' + currentPackageHash; const local_address = context.filesDir; - fs.moveFileSync(sx_latestJSBundleFile_bundle,local_address + '/bundle.harmony.js') - Logger.info(TAG, "restartAppInternal--loadBundle-moveFileSync"); + let listFileOption: ListFileOptions = { + recursion: false, + listNum: 0 + } try { - FileUtils.copyDirectoryAll(sx_latestJSBundleFile_assets,local_address) - } catch (error) { + let filenames = fs.listFileSync(sx_latestJSBundleFile, listFileOption); + const getBundleCont = sx_latestJSBundleFile + '/' + filenames[0]; + const new_getBundleCont = sx_latestJSBundleFile + '/Bundles'; + fs.renameSync(getBundleCont,new_getBundleCont); + fs.copyDirSync(new_getBundleCont,local_address,1) + }catch (error) { Logger.error(TAG, `restartAppInternal--loadBundle-end,error=${JSON.stringify(error)}`); } Logger.info(TAG, "restartAppInternal--loadBundle-end"); - this.ctx.devToolsController.eventEmitter.emit("RELOAD", { reason: 'HotReload2' }) + if(this.installMode === 0){ + this.ctx.devToolsController.eventEmitter.emit("RELOAD", { reason: 'HotReload2' }) + } Logger.info(TAG, "restartAppInternal RELOAD end"); }