Skip to content

Commit bfb520b

Browse files
committed
add currentversioninfo
1 parent f7be8a4 commit bfb520b

File tree

9 files changed

+47
-23
lines changed

9 files changed

+47
-23
lines changed

android/src/newarch/cn/reactnative/modules/update/UpdateModule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ protected Map<String, Object> getTypedExportedConstants() {
3535
final Map<String, Object> constants = new HashMap<>();
3636
constants.put("downloadRootDir", updateContext.getRootDir());
3737
constants.put("packageVersion", updateContext.getPackageVersion());
38-
constants.put("currentVersion", updateContext.getCurrentVersion());
38+
String currentVersion = updateContext.getCurrentVersion();
39+
constants.put("currentVersion", currentVersion);
40+
constants.put("currentVersionInfo", updateContext.getKv("hash_" + currentVersion));
3941
constants.put("buildTime", updateContext.getBuildTime());
4042
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
4143
boolean isFirstTime = updateContext.isFirstTime();

android/src/oldarch/cn/reactnative/modules/update/UpdateModule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public Map<String, Object> getConstants() {
4848
final Map<String, Object> constants = new HashMap<>();
4949
constants.put("downloadRootDir", updateContext.getRootDir());
5050
constants.put("packageVersion", updateContext.getPackageVersion());
51-
constants.put("currentVersion", updateContext.getCurrentVersion());
51+
String currentVersion = updateContext.getCurrentVersion();
52+
constants.put("currentVersion", currentVersion);
53+
constants.put("currentVersionInfo", updateContext.getKv("hash_" + currentVersion));
5254
constants.put("buildTime", updateContext.getBuildTime());
5355
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
5456
boolean isFirstTime = updateContext.isFirstTime();

harmony/pushy/src/main/ets/PushyTurboModule.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ getConstants(): Object {
3232
const rolledBackVersion = preferencesManager.getSync("rolledBackVersion", "") as string;
3333
const uuid = preferencesManager.getSync("uuid", "") as string;
3434
const currentVersion = preferencesManager.getSync("currentVersion", "") as string;
35+
const currentVersionInfo = this.context.getKv(`hash_${currentVersion}`);
3536
const buildTime = preferencesManager.getSync("buildTime", "") as string;
3637
const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
3738
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
@@ -53,6 +54,7 @@ getConstants(): Object {
5354

5455
return {
5556
downloadRootDir: `${context.filesDir}/_update`,
57+
currentVersionInfo,
5658
packageVersion,
5759
currentVersion,
5860
buildTime,
@@ -64,13 +66,13 @@ getConstants(): Object {
6466
}
6567

6668

67-
async setLocalHashInfo(hash: string, info: string): Promise<boolean> {
69+
setLocalHashInfo(hash: string, info: string): boolean {
6870
logger.debug(TAG, ",call setLocalHashInfo");
69-
return UpdateModuleImpl.setLocalHashInfo(this.context,hash,info);
71+
return UpdateModuleImpl.setLocalHashInfo(this.context, hash, info);
7072
}
7173

72-
async getLocalHashInfo(hash: string): Promise<string> {
73-
return UpdateModuleImpl.getLocalHashInfo(this.context,hash);
74+
getLocalHashInfo(hash: string): string {
75+
return UpdateModuleImpl.getLocalHashInfo(this.context, hash);
7476
}
7577

7678
async setUuid(uuid: string): Promise<boolean> {

harmony/pushy/src/main/ets/UpdateContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export class UpdateContext {
5050
this.preferences.flush();
5151
}
5252

53-
public getKv(key: string): string {
54-
return this.preferences.getSync(key, '') as string;
53+
public getKv(key: string): string {
54+
return this.preferences.getSync(key, '') as string;
5555
}
5656

5757
public isFirstTime(): boolean {

harmony/pushy/src/main/ets/UpdateModuleImpl.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,27 +171,20 @@ export class UpdateModuleImpl {
171171
}
172172
}
173173

174-
static async setLocalHashInfo(
174+
static setLocalHashInfo(
175175
updateContext: UpdateContext,
176176
hash: string,
177177
info: string
178-
): Promise<boolean> {
179-
if (!this.checkJson(info)) {
180-
await updateContext.setKv(`hash_${hash}`, info);
181-
throw new Error('校验报错:json字符串格式错误');
182-
}
183-
await updateContext.setKv(`hash_${hash}`, info);
178+
): boolean {
179+
updateContext.setKv(`hash_${hash}`, info);
184180
return true;
185181
}
186182

187-
static async getLocalHashInfo(
183+
static getLocalHashInfo(
188184
updateContext: UpdateContext,
189185
hash: string
190-
): Promise<string> {
191-
const value = await updateContext.getKv(`hash_${hash}`);
192-
if (!this.checkJson(value)) {
193-
throw new Error('校验报错:json字符串格式错误');
194-
}
186+
): string {
187+
const value = updateContext.getKv(`hash_${hash}`);
195188
return value;
196189
}
197190
}

ios/RCTPushy/RCTPushy.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ - (NSDictionary *)constantsToExport
176176
ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked];
177177
ret[@"uuid"] = [defaults objectForKey:keyUuid];
178178
NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
179-
ret[@"currentVersion"] = [pushyInfo objectForKey:paramCurrentVersion];
179+
NSString *currentVersion = [pushyInfo objectForKey:paramCurrentVersion];
180+
ret[@"currentVersion"] = currentVersion;
181+
ret[@"currentVersionInfo"] = [pushyInfo objectForKey:[keyHashInfo stringByAppendingString:currentVersion]];
180182

181183
// clear isFirstTimemarked
182184
if (ret[@"isFirstTime"]) {

src/context.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ export const UpdateContext = createContext<{
2828
dismissError: () => void;
2929
downloadUpdate: () => Promise<boolean | void>;
3030
downloadAndInstallApk: (url: string) => Promise<void>;
31+
// @deprecated use currentVersionInfo instead
3132
getCurrentVersionInfo: () => Promise<{
3233
name?: string;
3334
description?: string;
3435
metaInfo?: string;
3536
}>;
37+
currentVersionInfo: {
38+
name?: string;
39+
description?: string;
40+
metaInfo?: string;
41+
} | null;
3642
parseTestQrCode: (code: string) => boolean;
3743
restartApp: () => Promise<void>;
3844
currentHash: string;

src/core.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ const PushyConstants = isTurboModuleEnabled
3030
export const downloadRootDir: string = PushyConstants.downloadRootDir;
3131
export const packageVersion: string = PushyConstants.packageVersion;
3232
export const currentVersion: string = PushyConstants.currentVersion;
33+
34+
const currentVersionInfoString: string = PushyConstants.currentVersionInfo;
35+
let _currentVersionInfo = {};
36+
if (currentVersionInfoString) {
37+
try {
38+
_currentVersionInfo = JSON.parse(currentVersionInfoString);
39+
} catch (error) {
40+
console.error(
41+
'Failed to parse currentVersionInfo:',
42+
currentVersionInfoString,
43+
);
44+
}
45+
}
46+
export const currentVersionInfo = _currentVersionInfo;
47+
3348
export const isFirstTime: boolean = PushyConstants.isFirstTime;
3449
export const rolledBackVersion: string = PushyConstants.rolledBackVersion;
3550
export const isRolledBack: boolean = typeof rolledBackVersion === 'string';
@@ -45,6 +60,7 @@ async function getLocalHashInfo(hash: string) {
4560
return JSON.parse(await PushyModule.getLocalHashInfo(hash));
4661
}
4762

63+
// @deprecated use currentVersionInfo instead
4864
export async function getCurrentVersionInfo(): Promise<{
4965
name?: string;
5066
description?: string;

src/provider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
Linking,
1414
} from 'react-native';
1515
import { Pushy, Cresc, sharedState } from './client';
16-
import { currentVersion, packageVersion, getCurrentVersionInfo } from './core';
16+
import { currentVersion, packageVersion, getCurrentVersionInfo, currentVersionInfo } from './core';
1717
import {
1818
CheckResult,
1919
MixedCheckResult,
@@ -400,6 +400,7 @@ export const UpdateProvider = ({
400400
progress,
401401
downloadAndInstallApk,
402402
getCurrentVersionInfo,
403+
currentVersionInfo,
403404
parseTestQrCode,
404405
restartApp,
405406
}}>

0 commit comments

Comments
 (0)