1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-10-23 09:38:52 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

add currentversioninfo

This commit is contained in:
sunnylqm
2025-09-15 23:46:19 +08:00
parent f7be8a4d71
commit bfb520bd07
9 changed files with 47 additions and 23 deletions

View File

@@ -35,7 +35,9 @@ public class UpdateModule extends NativePushySpec {
final Map<String, Object> 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();

View File

@@ -48,7 +48,9 @@ public class UpdateModule extends ReactContextBaseJavaModule {
final Map<String, Object> 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();

View File

@@ -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,12 +66,12 @@ getConstants(): Object {
}
async setLocalHashInfo(hash: string, info: string): Promise<boolean> {
setLocalHashInfo(hash: string, info: string): boolean {
logger.debug(TAG, ",call setLocalHashInfo");
return UpdateModuleImpl.setLocalHashInfo(this.context, hash, info);
}
async getLocalHashInfo(hash: string): Promise<string> {
getLocalHashInfo(hash: string): string {
return UpdateModuleImpl.getLocalHashInfo(this.context, hash);
}

View File

@@ -171,27 +171,20 @@ export class UpdateModuleImpl {
}
}
static async setLocalHashInfo(
static setLocalHashInfo(
updateContext: UpdateContext,
hash: string,
info: string
): Promise<boolean> {
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<string> {
const value = await updateContext.getKv(`hash_${hash}`);
if (!this.checkJson(value)) {
throw new Error('校验报错:json字符串格式错误');
}
): string {
const value = updateContext.getKv(`hash_${hash}`);
return value;
}
}

View File

@@ -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"]) {

View File

@@ -28,11 +28,17 @@ export const UpdateContext = createContext<{
dismissError: () => void;
downloadUpdate: () => Promise<boolean | void>;
downloadAndInstallApk: (url: string) => Promise<void>;
// @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<void>;
currentHash: string;

View File

@@ -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;

View File

@@ -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,
}}>