diff --git a/harmony/codePush/src/main/ets/CodePush.ts b/harmony/codePush/src/main/ets/CodePush.ts index 47906818d..e572f5236 100644 --- a/harmony/codePush/src/main/ets/CodePush.ts +++ b/harmony/codePush/src/main/ets/CodePush.ts @@ -58,12 +58,12 @@ export class CodePush { } this.mCurrentInstance = this; - const publicKeyFromStrings: string = this.getCustomPropertyFromStringsIfExist("PublicKey"); + const publicKeyFromStrings: string = AppStorage.Get("CodePushConfig")["PublicKey"];; if (publicKeyFromStrings != null) { CodePush.mPublicKey = publicKeyFromStrings; } - const serverUrlFromStrings: string = this.getCustomPropertyFromStringsIfExist("ServerUrl"); + const serverUrlFromStrings: string = AppStorage.Get("CodePushConfig")["ServerUrl"]; if (serverUrlFromStrings != null) { this.mServerUrl = serverUrlFromStrings; } diff --git a/harmony/codePush/src/main/ets/CodePushBuilder.ts b/harmony/codePush/src/main/ets/CodePushBuilder.ts index 21034fd01..be3970a53 100644 --- a/harmony/codePush/src/main/ets/CodePushBuilder.ts +++ b/harmony/codePush/src/main/ets/CodePushBuilder.ts @@ -23,9 +23,9 @@ export class CodePushBuilder { if (isDebug) { deploymentKeyConfigName = 'Staging'; } else { - deploymentKeyConfigName = 'production'; + deploymentKeyConfigName = 'Production'; } - let deploymentKey = context.resourceManager.getStringByNameSync(deploymentKeyConfigName); + let deploymentKey = AppStorage.Get("CodePushConfig")[deploymentKeyConfigName]; this.mDeploymentKey = deploymentKey; Logger.info(TAG, `CodePushBuilder getDeploymentKey:${deploymentKey}`) } diff --git a/harmony/codePush/src/main/ets/CodePushNativeModule.ts b/harmony/codePush/src/main/ets/CodePushNativeModule.ts index cc413058a..7fab35862 100644 --- a/harmony/codePush/src/main/ets/CodePushNativeModule.ts +++ b/harmony/codePush/src/main/ets/CodePushNativeModule.ts @@ -7,6 +7,7 @@ import { CodePushTelemetryManager } from './CodePushTelemetryManager'; import { CodePush } from './CodePush'; import common from '@ohos.app.ability.common'; import fs from '@ohos.file.fs'; +import FileUtils from './FileUtils'; import { SettingsManager } from './SettingsManager'; import { BusinessError } from '@kit.BasicServicesKit'; import { CodePushUtils } from './CodePushUtils'; @@ -86,10 +87,10 @@ export class CodePushNativeModule extends TurboModule implements TM.RTNCodePush. let bundleFileName: string = 'bundle.harmony.js'; return new CodePushUpdateManager('').downloadPackage(mutableUpdatePackage, bundleFileName, this.ctx.httpClient, - (totalSize, receiveSize) => { + (totalBytes, receivedBytes) => { this.ctx.rnInstance.emitDeviceEvent('CodePushDownloadProgress', { - totalSize: totalSize, - receiveSize: receiveSize, + totalBytes: totalBytes, + receivedBytes: receivedBytes, }); }, '') @@ -380,19 +381,13 @@ 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 = - context.filesDir + '/CodePush/' + currentPackageHash + '/bundle.harmony.js' - const local_address = context.filesDir + '/bundle.harmony.js' - Logger.info(TAG, `loadBundle sx_latestJSBundleFile=${sx_latestJSBundleFile}`); - let access = fs.accessSync(sx_latestJSBundleFile); - Logger.info(TAG, `loadBundle sx_latestJSBundleFile access=${access}`); - Logger.info(TAG, `loadBundle local_address=${local_address}`); - // 加载下载的bundle包 start - ///data/app/el2/100/base/com.rnoh.CodeP/haps/entry/files/CodePush/eb6edb31a178973959241cd459aed87aa521d230dff2d53486fcdf4842225ae9 - fs.unlinkSync(local_address); - Logger.info(TAG, `loadBundle unlinkSync local_address`); + let sx_latestJSBundleFile_assets = context.filesDir + '/CodePush/' + currentPackageHash + '/rawfile/assets'; + let sx_latestJSBundleFile_bundle = context.filesDir + '/CodePush/' + currentPackageHash + '/rawfile/bundle.harmony.js'; + const local_address = context.filesDir; + fs.moveFileSync(sx_latestJSBundleFile_bundle,local_address + '/bundle.harmony.js') + Logger.info(TAG, "restartAppInternal--loadBundle-moveFileSync"); try { - fs.copyFileSync(sx_latestJSBundleFile, local_address); + FileUtils.copyDirectoryAll(sx_latestJSBundleFile_assets,local_address) } catch (error) { Logger.error(TAG, `restartAppInternal--loadBundle-end,error=${JSON.stringify(error)}`); } diff --git a/harmony/codePush/src/main/ets/CodePushUpdateUtils.ts b/harmony/codePush/src/main/ets/CodePushUpdateUtils.ts index aedb48b4a..867f7b90b 100644 --- a/harmony/codePush/src/main/ets/CodePushUpdateUtils.ts +++ b/harmony/codePush/src/main/ets/CodePushUpdateUtils.ts @@ -39,7 +39,7 @@ export class CodePushUpdateUtils { public static getHashForBinaryContents(context, isDebugMode: boolean): string { Logger.info(TAG, `getHashForBinaryContents isDebugMode:${isDebugMode.toString()}`); - let filesDir = context.filesDir; + let filesDir = context.filesDir+'/'; try { let file = fs.openSync( filesDir + CodePushConstants.CODE_PUSH_HASH_FILE_NAME, diff --git a/harmony/codePush/src/main/ets/FileUtils.ts b/harmony/codePush/src/main/ets/FileUtils.ts index 01c7af725..fd3bfbbf6 100644 --- a/harmony/codePush/src/main/ets/FileUtils.ts +++ b/harmony/codePush/src/main/ets/FileUtils.ts @@ -41,7 +41,23 @@ export default class FileUtils { fs.copyFileSync(currentPackageFolderPath, newPackageFolderPath); } } - + //将原路径下的所有文件夹复制到另一个文件夹下 + static copyDirectoryAll(currentPath:string,newPath:string){ + let listFileOption: ListFileOptions = { + recursion: false, + listNum: 0 + } + try { + let filenames = fs.listFileSync(currentPath,listFileOption); + Logger.info(TAG,`copyDirectoryAll--filenames:${JSON.stringify(filenames)}`) + for (let i = 0; i < filenames.length; i++) { + const srcEntryPath = `${currentPath}/${filenames[i]}`; + fs.copyDirSync(srcEntryPath,newPath,1) + } + } catch (error) { + Logger.info(TAG,`copyDirectoryAll--error:${error}`) + } + } //删除指定路径下的目录。 static deleteDirectoryAtPath(directoryPath: string): void { if (directoryPath == null) {