mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-10-23 09:38:52 +08:00
add currentversioninfo
This commit is contained in:
@@ -35,7 +35,9 @@ public class UpdateModule extends NativePushySpec {
|
|||||||
final Map<String, Object> constants = new HashMap<>();
|
final Map<String, Object> constants = new HashMap<>();
|
||||||
constants.put("downloadRootDir", updateContext.getRootDir());
|
constants.put("downloadRootDir", updateContext.getRootDir());
|
||||||
constants.put("packageVersion", updateContext.getPackageVersion());
|
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("buildTime", updateContext.getBuildTime());
|
||||||
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
|
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
|
||||||
boolean isFirstTime = updateContext.isFirstTime();
|
boolean isFirstTime = updateContext.isFirstTime();
|
||||||
|
@@ -48,7 +48,9 @@ public class UpdateModule extends ReactContextBaseJavaModule {
|
|||||||
final Map<String, Object> constants = new HashMap<>();
|
final Map<String, Object> constants = new HashMap<>();
|
||||||
constants.put("downloadRootDir", updateContext.getRootDir());
|
constants.put("downloadRootDir", updateContext.getRootDir());
|
||||||
constants.put("packageVersion", updateContext.getPackageVersion());
|
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("buildTime", updateContext.getBuildTime());
|
||||||
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
|
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
|
||||||
boolean isFirstTime = updateContext.isFirstTime();
|
boolean isFirstTime = updateContext.isFirstTime();
|
||||||
|
@@ -32,6 +32,7 @@ getConstants(): Object {
|
|||||||
const rolledBackVersion = preferencesManager.getSync("rolledBackVersion", "") as string;
|
const rolledBackVersion = preferencesManager.getSync("rolledBackVersion", "") as string;
|
||||||
const uuid = preferencesManager.getSync("uuid", "") as string;
|
const uuid = preferencesManager.getSync("uuid", "") as string;
|
||||||
const currentVersion = preferencesManager.getSync("currentVersion", "") as string;
|
const currentVersion = preferencesManager.getSync("currentVersion", "") as string;
|
||||||
|
const currentVersionInfo = this.context.getKv(`hash_${currentVersion}`);
|
||||||
const buildTime = preferencesManager.getSync("buildTime", "") as string;
|
const buildTime = preferencesManager.getSync("buildTime", "") as string;
|
||||||
const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
|
const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
|
||||||
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
||||||
@@ -53,6 +54,7 @@ getConstants(): Object {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
downloadRootDir: `${context.filesDir}/_update`,
|
downloadRootDir: `${context.filesDir}/_update`,
|
||||||
|
currentVersionInfo,
|
||||||
packageVersion,
|
packageVersion,
|
||||||
currentVersion,
|
currentVersion,
|
||||||
buildTime,
|
buildTime,
|
||||||
@@ -64,13 +66,13 @@ getConstants(): Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async setLocalHashInfo(hash: string, info: string): Promise<boolean> {
|
setLocalHashInfo(hash: string, info: string): boolean {
|
||||||
logger.debug(TAG, ",call setLocalHashInfo");
|
logger.debug(TAG, ",call setLocalHashInfo");
|
||||||
return UpdateModuleImpl.setLocalHashInfo(this.context,hash,info);
|
return UpdateModuleImpl.setLocalHashInfo(this.context, hash, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLocalHashInfo(hash: string): Promise<string> {
|
getLocalHashInfo(hash: string): string {
|
||||||
return UpdateModuleImpl.getLocalHashInfo(this.context,hash);
|
return UpdateModuleImpl.getLocalHashInfo(this.context, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setUuid(uuid: string): Promise<boolean> {
|
async setUuid(uuid: string): Promise<boolean> {
|
||||||
|
@@ -50,8 +50,8 @@ export class UpdateContext {
|
|||||||
this.preferences.flush();
|
this.preferences.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getKv(key: string): string {
|
public getKv(key: string): string {
|
||||||
return this.preferences.getSync(key, '') as string;
|
return this.preferences.getSync(key, '') as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public isFirstTime(): boolean {
|
public isFirstTime(): boolean {
|
||||||
|
@@ -171,27 +171,20 @@ export class UpdateModuleImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setLocalHashInfo(
|
static setLocalHashInfo(
|
||||||
updateContext: UpdateContext,
|
updateContext: UpdateContext,
|
||||||
hash: string,
|
hash: string,
|
||||||
info: string
|
info: string
|
||||||
): Promise<boolean> {
|
): boolean {
|
||||||
if (!this.checkJson(info)) {
|
updateContext.setKv(`hash_${hash}`, info);
|
||||||
await updateContext.setKv(`hash_${hash}`, info);
|
|
||||||
throw new Error('校验报错:json字符串格式错误');
|
|
||||||
}
|
|
||||||
await updateContext.setKv(`hash_${hash}`, info);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getLocalHashInfo(
|
static getLocalHashInfo(
|
||||||
updateContext: UpdateContext,
|
updateContext: UpdateContext,
|
||||||
hash: string
|
hash: string
|
||||||
): Promise<string> {
|
): string {
|
||||||
const value = await updateContext.getKv(`hash_${hash}`);
|
const value = updateContext.getKv(`hash_${hash}`);
|
||||||
if (!this.checkJson(value)) {
|
|
||||||
throw new Error('校验报错:json字符串格式错误');
|
|
||||||
}
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -176,7 +176,9 @@ RCT_EXPORT_MODULE(RCTPushy);
|
|||||||
ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked];
|
ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked];
|
||||||
ret[@"uuid"] = [defaults objectForKey:keyUuid];
|
ret[@"uuid"] = [defaults objectForKey:keyUuid];
|
||||||
NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
|
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
|
// clear isFirstTimemarked
|
||||||
if (ret[@"isFirstTime"]) {
|
if (ret[@"isFirstTime"]) {
|
||||||
|
@@ -28,11 +28,17 @@ export const UpdateContext = createContext<{
|
|||||||
dismissError: () => void;
|
dismissError: () => void;
|
||||||
downloadUpdate: () => Promise<boolean | void>;
|
downloadUpdate: () => Promise<boolean | void>;
|
||||||
downloadAndInstallApk: (url: string) => Promise<void>;
|
downloadAndInstallApk: (url: string) => Promise<void>;
|
||||||
|
// @deprecated use currentVersionInfo instead
|
||||||
getCurrentVersionInfo: () => Promise<{
|
getCurrentVersionInfo: () => Promise<{
|
||||||
name?: string;
|
name?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
metaInfo?: string;
|
metaInfo?: string;
|
||||||
}>;
|
}>;
|
||||||
|
currentVersionInfo: {
|
||||||
|
name?: string;
|
||||||
|
description?: string;
|
||||||
|
metaInfo?: string;
|
||||||
|
} | null;
|
||||||
parseTestQrCode: (code: string) => boolean;
|
parseTestQrCode: (code: string) => boolean;
|
||||||
restartApp: () => Promise<void>;
|
restartApp: () => Promise<void>;
|
||||||
currentHash: string;
|
currentHash: string;
|
||||||
|
16
src/core.ts
16
src/core.ts
@@ -30,6 +30,21 @@ const PushyConstants = isTurboModuleEnabled
|
|||||||
export const downloadRootDir: string = PushyConstants.downloadRootDir;
|
export const downloadRootDir: string = PushyConstants.downloadRootDir;
|
||||||
export const packageVersion: string = PushyConstants.packageVersion;
|
export const packageVersion: string = PushyConstants.packageVersion;
|
||||||
export const currentVersion: string = PushyConstants.currentVersion;
|
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 isFirstTime: boolean = PushyConstants.isFirstTime;
|
||||||
export const rolledBackVersion: string = PushyConstants.rolledBackVersion;
|
export const rolledBackVersion: string = PushyConstants.rolledBackVersion;
|
||||||
export const isRolledBack: boolean = typeof rolledBackVersion === 'string';
|
export const isRolledBack: boolean = typeof rolledBackVersion === 'string';
|
||||||
@@ -45,6 +60,7 @@ async function getLocalHashInfo(hash: string) {
|
|||||||
return JSON.parse(await PushyModule.getLocalHashInfo(hash));
|
return JSON.parse(await PushyModule.getLocalHashInfo(hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @deprecated use currentVersionInfo instead
|
||||||
export async function getCurrentVersionInfo(): Promise<{
|
export async function getCurrentVersionInfo(): Promise<{
|
||||||
name?: string;
|
name?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
@@ -13,7 +13,7 @@ import {
|
|||||||
Linking,
|
Linking,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { Pushy, Cresc, sharedState } from './client';
|
import { Pushy, Cresc, sharedState } from './client';
|
||||||
import { currentVersion, packageVersion, getCurrentVersionInfo } from './core';
|
import { currentVersion, packageVersion, getCurrentVersionInfo, currentVersionInfo } from './core';
|
||||||
import {
|
import {
|
||||||
CheckResult,
|
CheckResult,
|
||||||
MixedCheckResult,
|
MixedCheckResult,
|
||||||
@@ -400,6 +400,7 @@ export const UpdateProvider = ({
|
|||||||
progress,
|
progress,
|
||||||
downloadAndInstallApk,
|
downloadAndInstallApk,
|
||||||
getCurrentVersionInfo,
|
getCurrentVersionInfo,
|
||||||
|
currentVersionInfo,
|
||||||
parseTestQrCode,
|
parseTestQrCode,
|
||||||
restartApp,
|
restartApp,
|
||||||
}}>
|
}}>
|
||||||
|
Reference in New Issue
Block a user