mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-12-20 04:35:13 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aee9345e3d | ||
|
|
6c07aa7518 |
@@ -46,20 +46,9 @@ public class UpdateContext {
|
||||
|
||||
|
||||
SharedPreferences.Editor editor = this.sp.edit();
|
||||
if (storedPackageVersion == null) {
|
||||
editor.putString("packageVersion", packageVersion);
|
||||
editor.apply();
|
||||
storedPackageVersion = packageVersion;
|
||||
}
|
||||
|
||||
if (storedBuildTime == null) {
|
||||
editor.putString("buildTime", buildTime);
|
||||
editor.apply();
|
||||
storedBuildTime = buildTime;
|
||||
}
|
||||
|
||||
boolean packageVersionChanged = !packageVersion.equals(storedPackageVersion);
|
||||
boolean buildTimeChanged = !buildTime.equals(storedBuildTime);
|
||||
boolean packageVersionChanged = storedPackageVersion == null || !packageVersion.equals(storedPackageVersion);
|
||||
boolean buildTimeChanged = storedBuildTime == null || !buildTime.equals(storedBuildTime);
|
||||
|
||||
if (packageVersionChanged || buildTimeChanged) {
|
||||
// Execute cleanUp before clearing SharedPreferences to avoid race condition
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "10.36.5",
|
||||
"version": "10.37.0",
|
||||
"description": "react-native hot update",
|
||||
"main": "src/index",
|
||||
"scripts": {
|
||||
|
||||
@@ -65,6 +65,7 @@ const defaultClientOptions: ClientOptions = {
|
||||
export const sharedState: {
|
||||
progressHandlers: Record<string, EmitterSubscription>;
|
||||
downloadedHash?: string;
|
||||
toHash?: string;
|
||||
apkStatus: 'downloading' | 'downloaded' | null;
|
||||
marked: boolean;
|
||||
applyingUpdate: boolean;
|
||||
@@ -509,11 +510,15 @@ export class Pushy {
|
||||
});
|
||||
}
|
||||
log(`downloaded ${succeeded} hash:`, hash);
|
||||
setLocalHashInfo(hash, {
|
||||
const hashInfo: Record<string, any> = {
|
||||
name,
|
||||
description,
|
||||
metaInfo,
|
||||
});
|
||||
};
|
||||
if (sharedState.toHash === hash) {
|
||||
hashInfo.debugChannel = true;
|
||||
}
|
||||
setLocalHashInfo(hash, hashInfo);
|
||||
sharedState.downloadedHash = hash;
|
||||
return hash;
|
||||
};
|
||||
|
||||
16
src/core.ts
16
src/core.ts
@@ -31,11 +31,21 @@ export const downloadRootDir: string = PushyConstants.downloadRootDir;
|
||||
export const packageVersion: string = PushyConstants.packageVersion;
|
||||
export const currentVersion: string = PushyConstants.currentVersion;
|
||||
|
||||
export function setLocalHashInfo(hash: string, info: Record<string, any>) {
|
||||
PushyModule.setLocalHashInfo(hash, JSON.stringify(info));
|
||||
}
|
||||
|
||||
const currentVersionInfoString: string = PushyConstants.currentVersionInfo;
|
||||
let _currentVersionInfo = {};
|
||||
let _currentVersionInfo: Record<string, any> = {};
|
||||
let isDebugChannel = false;
|
||||
if (currentVersionInfoString) {
|
||||
try {
|
||||
_currentVersionInfo = JSON.parse(currentVersionInfoString);
|
||||
if (_currentVersionInfo.debugChannel) {
|
||||
isDebugChannel = true;
|
||||
delete _currentVersionInfo.debugChannel;
|
||||
setLocalHashInfo(currentVersion, _currentVersionInfo);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(
|
||||
'Failed to parse currentVersionInfo:',
|
||||
@@ -46,15 +56,13 @@ if (currentVersionInfoString) {
|
||||
export const currentVersionInfo = _currentVersionInfo;
|
||||
|
||||
export const isFirstTime: boolean = PushyConstants.isFirstTime;
|
||||
export const isFirstTimeDebug: boolean = isFirstTime && isDebugChannel;
|
||||
export const rolledBackVersion: string = PushyConstants.rolledBackVersion;
|
||||
export const isRolledBack: boolean = !!rolledBackVersion;
|
||||
|
||||
export const buildTime: string = PushyConstants.buildTime;
|
||||
let uuid = PushyConstants.uuid;
|
||||
|
||||
export function setLocalHashInfo(hash: string, info: Record<string, any>) {
|
||||
PushyModule.setLocalHashInfo(hash, JSON.stringify(info));
|
||||
}
|
||||
|
||||
async function getLocalHashInfo(hash: string) {
|
||||
return JSON.parse(await PushyModule.getLocalHashInfo(hash));
|
||||
|
||||
@@ -327,7 +327,9 @@ export const UpdateProvider = ({
|
||||
Alert.alert(type, JSON.stringify(data));
|
||||
};
|
||||
if (payload.type === '__rnPushyVersionHash') {
|
||||
checkUpdate({ extra: { toHash: payload.data } }).then(() => {
|
||||
const toHash = payload.data;
|
||||
sharedState.toHash = toHash;
|
||||
checkUpdate({ extra: { toHash } }).then(() => {
|
||||
if (updateInfoRef.current && updateInfoRef.current.upToDate) {
|
||||
Alert.alert(
|
||||
client.t('alert_info'),
|
||||
|
||||
Reference in New Issue
Block a user