From bfb520bd07f68cea352300f5e518d5c1ca1f4a29 Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Mon, 15 Sep 2025 23:46:19 +0800 Subject: [PATCH] add currentversioninfo --- .../modules/update/UpdateModule.java | 4 +++- .../modules/update/UpdateModule.java | 4 +++- .../pushy/src/main/ets/PushyTurboModule.ts | 10 ++++++---- harmony/pushy/src/main/ets/UpdateContext.ts | 4 ++-- .../pushy/src/main/ets/UpdateModuleImpl.ts | 19 ++++++------------- ios/RCTPushy/RCTPushy.mm | 4 +++- src/context.ts | 6 ++++++ src/core.ts | 16 ++++++++++++++++ src/provider.tsx | 3 ++- 9 files changed, 47 insertions(+), 23 deletions(-) diff --git a/android/src/newarch/cn/reactnative/modules/update/UpdateModule.java b/android/src/newarch/cn/reactnative/modules/update/UpdateModule.java index 3d13a9d..16c9630 100644 --- a/android/src/newarch/cn/reactnative/modules/update/UpdateModule.java +++ b/android/src/newarch/cn/reactnative/modules/update/UpdateModule.java @@ -35,7 +35,9 @@ public class UpdateModule extends NativePushySpec { final Map constants = new HashMap<>(); constants.put("downloadRootDir", updateContext.getRootDir()); constants.put("packageVersion", updateContext.getPackageVersion()); - constants.put("currentVersion", updateContext.getCurrentVersion()); + String currentVersion = updateContext.getCurrentVersion(); + constants.put("currentVersion", currentVersion); + constants.put("currentVersionInfo", updateContext.getKv("hash_" + currentVersion)); constants.put("buildTime", updateContext.getBuildTime()); constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl()); boolean isFirstTime = updateContext.isFirstTime(); diff --git a/android/src/oldarch/cn/reactnative/modules/update/UpdateModule.java b/android/src/oldarch/cn/reactnative/modules/update/UpdateModule.java index ca3e7ba..526b518 100644 --- a/android/src/oldarch/cn/reactnative/modules/update/UpdateModule.java +++ b/android/src/oldarch/cn/reactnative/modules/update/UpdateModule.java @@ -48,7 +48,9 @@ public class UpdateModule extends ReactContextBaseJavaModule { final Map constants = new HashMap<>(); constants.put("downloadRootDir", updateContext.getRootDir()); constants.put("packageVersion", updateContext.getPackageVersion()); - constants.put("currentVersion", updateContext.getCurrentVersion()); + String currentVersion = updateContext.getCurrentVersion(); + constants.put("currentVersion", currentVersion); + constants.put("currentVersionInfo", updateContext.getKv("hash_" + currentVersion)); constants.put("buildTime", updateContext.getBuildTime()); constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl()); boolean isFirstTime = updateContext.isFirstTime(); diff --git a/harmony/pushy/src/main/ets/PushyTurboModule.ts b/harmony/pushy/src/main/ets/PushyTurboModule.ts index 0edfced..70723d9 100644 --- a/harmony/pushy/src/main/ets/PushyTurboModule.ts +++ b/harmony/pushy/src/main/ets/PushyTurboModule.ts @@ -32,6 +32,7 @@ getConstants(): Object { const rolledBackVersion = preferencesManager.getSync("rolledBackVersion", "") as string; const uuid = preferencesManager.getSync("uuid", "") as string; const currentVersion = preferencesManager.getSync("currentVersion", "") as string; + const currentVersionInfo = this.context.getKv(`hash_${currentVersion}`); const buildTime = preferencesManager.getSync("buildTime", "") as string; const isUsingBundleUrl = this.context.getIsUsingBundleUrl(); let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; @@ -53,6 +54,7 @@ getConstants(): Object { return { downloadRootDir: `${context.filesDir}/_update`, + currentVersionInfo, packageVersion, currentVersion, buildTime, @@ -64,13 +66,13 @@ getConstants(): Object { } - async setLocalHashInfo(hash: string, info: string): Promise { + setLocalHashInfo(hash: string, info: string): boolean { logger.debug(TAG, ",call setLocalHashInfo"); - return UpdateModuleImpl.setLocalHashInfo(this.context,hash,info); + return UpdateModuleImpl.setLocalHashInfo(this.context, hash, info); } - async getLocalHashInfo(hash: string): Promise { - return UpdateModuleImpl.getLocalHashInfo(this.context,hash); + getLocalHashInfo(hash: string): string { + return UpdateModuleImpl.getLocalHashInfo(this.context, hash); } async setUuid(uuid: string): Promise { diff --git a/harmony/pushy/src/main/ets/UpdateContext.ts b/harmony/pushy/src/main/ets/UpdateContext.ts index 7101a80..987ead0 100644 --- a/harmony/pushy/src/main/ets/UpdateContext.ts +++ b/harmony/pushy/src/main/ets/UpdateContext.ts @@ -50,8 +50,8 @@ export class UpdateContext { this.preferences.flush(); } - public getKv(key: string): string { - return this.preferences.getSync(key, '') as string; + public getKv(key: string): string { + return this.preferences.getSync(key, '') as string; } public isFirstTime(): boolean { diff --git a/harmony/pushy/src/main/ets/UpdateModuleImpl.ts b/harmony/pushy/src/main/ets/UpdateModuleImpl.ts index 9f2bd64..a97e458 100644 --- a/harmony/pushy/src/main/ets/UpdateModuleImpl.ts +++ b/harmony/pushy/src/main/ets/UpdateModuleImpl.ts @@ -171,27 +171,20 @@ export class UpdateModuleImpl { } } - static async setLocalHashInfo( + static setLocalHashInfo( updateContext: UpdateContext, hash: string, info: string - ): Promise { - if (!this.checkJson(info)) { - await updateContext.setKv(`hash_${hash}`, info); - throw new Error('校验报错:json字符串格式错误'); - } - await updateContext.setKv(`hash_${hash}`, info); + ): boolean { + updateContext.setKv(`hash_${hash}`, info); return true; } - static async getLocalHashInfo( + static getLocalHashInfo( updateContext: UpdateContext, hash: string - ): Promise { - const value = await updateContext.getKv(`hash_${hash}`); - if (!this.checkJson(value)) { - throw new Error('校验报错:json字符串格式错误'); - } + ): string { + const value = updateContext.getKv(`hash_${hash}`); return value; } } \ No newline at end of file diff --git a/ios/RCTPushy/RCTPushy.mm b/ios/RCTPushy/RCTPushy.mm index 15c847d..2d83b6a 100644 --- a/ios/RCTPushy/RCTPushy.mm +++ b/ios/RCTPushy/RCTPushy.mm @@ -176,7 +176,9 @@ RCT_EXPORT_MODULE(RCTPushy); ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked]; ret[@"uuid"] = [defaults objectForKey:keyUuid]; NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo]; - ret[@"currentVersion"] = [pushyInfo objectForKey:paramCurrentVersion]; + NSString *currentVersion = [pushyInfo objectForKey:paramCurrentVersion]; + ret[@"currentVersion"] = currentVersion; + ret[@"currentVersionInfo"] = [pushyInfo objectForKey:[keyHashInfo stringByAppendingString:currentVersion]]; // clear isFirstTimemarked if (ret[@"isFirstTime"]) { diff --git a/src/context.ts b/src/context.ts index a6297df..6ef5bcd 100644 --- a/src/context.ts +++ b/src/context.ts @@ -28,11 +28,17 @@ export const UpdateContext = createContext<{ dismissError: () => void; downloadUpdate: () => Promise; downloadAndInstallApk: (url: string) => Promise; + // @deprecated use currentVersionInfo instead getCurrentVersionInfo: () => Promise<{ name?: string; description?: string; metaInfo?: string; }>; + currentVersionInfo: { + name?: string; + description?: string; + metaInfo?: string; + } | null; parseTestQrCode: (code: string) => boolean; restartApp: () => Promise; currentHash: string; diff --git a/src/core.ts b/src/core.ts index 7ebe8b0..40f45f3 100644 --- a/src/core.ts +++ b/src/core.ts @@ -30,6 +30,21 @@ const PushyConstants = isTurboModuleEnabled export const downloadRootDir: string = PushyConstants.downloadRootDir; export const packageVersion: string = PushyConstants.packageVersion; export const currentVersion: string = PushyConstants.currentVersion; + +const currentVersionInfoString: string = PushyConstants.currentVersionInfo; +let _currentVersionInfo = {}; +if (currentVersionInfoString) { + try { + _currentVersionInfo = JSON.parse(currentVersionInfoString); + } catch (error) { + console.error( + 'Failed to parse currentVersionInfo:', + currentVersionInfoString, + ); + } +} +export const currentVersionInfo = _currentVersionInfo; + export const isFirstTime: boolean = PushyConstants.isFirstTime; export const rolledBackVersion: string = PushyConstants.rolledBackVersion; export const isRolledBack: boolean = typeof rolledBackVersion === 'string'; @@ -45,6 +60,7 @@ async function getLocalHashInfo(hash: string) { return JSON.parse(await PushyModule.getLocalHashInfo(hash)); } +// @deprecated use currentVersionInfo instead export async function getCurrentVersionInfo(): Promise<{ name?: string; description?: string; diff --git a/src/provider.tsx b/src/provider.tsx index 9b63260..d36f5af 100644 --- a/src/provider.tsx +++ b/src/provider.tsx @@ -13,7 +13,7 @@ import { Linking, } from 'react-native'; import { Pushy, Cresc, sharedState } from './client'; -import { currentVersion, packageVersion, getCurrentVersionInfo } from './core'; +import { currentVersion, packageVersion, getCurrentVersionInfo, currentVersionInfo } from './core'; import { CheckResult, MixedCheckResult, @@ -400,6 +400,7 @@ export const UpdateProvider = ({ progress, downloadAndInstallApk, getCurrentVersionInfo, + currentVersionInfo, parseTestQrCode, restartApp, }}>