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

Compare commits

...

20 Commits

Author SHA1 Message Date
sunnylqm
c26080325d v7.3.8 2021-11-22 18:11:22 +08:00
sunnylqm
ec0a9e0a3e Revert "Update pod script path"
This reverts commit fddae3d79a.
2021-11-11 18:46:48 +08:00
sunnylqm
b34b70ed01 v7.3.6 2021-11-11 18:09:21 +08:00
sunnylqm
fddae3d79a Update pod script path 2021-11-11 18:08:49 +08:00
sunnylqm
7fc0d717d5 v7.3.5 2021-11-10 22:31:56 +08:00
sunnylqm
686209d50e Check stateListener 2021-11-10 22:31:23 +08:00
sunnylqm
80b0401b02 v7.3.4 2021-11-04 17:53:05 +08:00
sunnylqm
786d32d92f Fix simpleUpdate 2021-11-04 17:52:30 +08:00
sunnylqm
27327dbe12 v7.3.3 2021-11-04 16:40:35 +08:00
sunnylqm
96a81cc36d Improve download exception handling 2021-11-04 16:39:50 +08:00
sunnylqm
0aa063c584 v7.3.2 2021-11-04 16:36:06 +08:00
sunnylqm
4d72d49fe4 Chech downloaded hash 2021-11-04 16:35:34 +08:00
sunnylqm
53d07406ef v7.3.1 2021-10-30 14:56:58 +08:00
sunnylqm
d0804cfe15 Fix rolledBackVersion 2021-10-30 14:56:23 +08:00
sunnylqm
35939286d0 v7.3.0 2021-10-29 13:03:34 +08:00
sunnylqm
f49ce30cef Fix assertHash 2021-10-29 13:02:49 +08:00
sunnylqm
e6cd25a2d8 v7.2.0 2021-10-24 16:19:48 +08:00
sunnylqm
0cc96ee59c Add error report 2021-10-24 16:19:17 +08:00
sunnylqm
6dd71a36e8 v7.1.0 2021-10-24 13:17:49 +08:00
sunnylqm
8db8d2162e Add report 2021-10-24 10:19:43 +08:00
8 changed files with 95 additions and 77 deletions

View File

@@ -68,6 +68,9 @@ export default class App extends Component {
});
},
});
if (!hash) {
return;
}
Alert.alert('提示', '下载完毕,是否重启应用?', [
{
text: '是',

View File

@@ -152,7 +152,7 @@ public class UpdateContext {
}
editor.putBoolean("firstTime", true);
editor.putBoolean("firstTimeOk", false);
editor.putBoolean("rolledBack", false);
editor.putString("rolledBackVersion", null);
editor.apply();
}
@@ -181,8 +181,8 @@ public class UpdateContext {
return sp.getBoolean("firstTime", false);
}
public boolean isRolledBack() {
return sp.getBoolean("rolledBack", false);
public String rolledBackVersion() {
return sp.getString("rolledBackVersion", null);
}
public void markSuccess() {
@@ -209,7 +209,7 @@ public class UpdateContext {
public void clearRollbackMark() {
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean("rolledBack", false);
editor.putString("rolledBackVersion", null);
editor.apply();
this.cleanUp();
@@ -265,6 +265,7 @@ public class UpdateContext {
private String rollBack() {
String lastVersion = sp.getString("lastVersion", null);
String currentVersion = sp.getString("currentVersion", null);
SharedPreferences.Editor editor = sp.edit();
if (lastVersion == null) {
editor.remove("currentVersion");
@@ -273,7 +274,7 @@ public class UpdateContext {
}
editor.putBoolean("firstTimeOk", true);
editor.putBoolean("firstTime", false);
editor.putBoolean("rolledBack", true);
editor.putString("rolledBackVersion", currentVersion);
editor.apply();
return lastVersion;
}

View File

@@ -54,9 +54,9 @@ public class UpdateModule extends ReactContextBaseJavaModule {
if (isFirstTime) {
updateContext.clearFirstTime();
}
boolean isRolledBack = updateContext.isRolledBack();
constants.put("isRolledBack", isRolledBack);
if (isRolledBack) {
String rolledBackVersion = updateContext.rolledBackVersion();
constants.put("rolledBackVersion", rolledBackVersion);
if (rolledBackVersion != null) {
updateContext.clearRollbackMark();
}
constants.put("blockUpdate", updateContext.getBlockUpdate());
@@ -134,9 +134,7 @@ public class UpdateModule extends ReactContextBaseJavaModule {
private void downloadPatchFromPackage(ReadableMap options, final Promise promise) {
String url = options.getString("updateUrl");
String hash = options.getString("hash");
if (hash == null) {
hash = options.getString("hashName");
}
updateContext.downloadPatchFromApk(url, hash, new UpdateContext.DownloadFileListener() {
@Override
public void onDownloadCompleted(DownloadTaskParams params) {
@@ -154,13 +152,9 @@ public class UpdateModule extends ReactContextBaseJavaModule {
private void downloadPatchFromPpk(ReadableMap options, final Promise promise) {
String url = options.getString("updateUrl");
String hash = options.getString("hash");
if (hash == null) {
hash = options.getString("hashName");
}
String originHash = options.getString("originHash");
if (originHash == null) {
originHash = options.getString(("originHashName"));
}
updateContext.downloadPatchFromPpk(url, hash, originHash, new UpdateContext.DownloadFileListener() {
@Override
public void onDownloadCompleted(DownloadTaskParams params) {
@@ -176,8 +170,7 @@ public class UpdateModule extends ReactContextBaseJavaModule {
@ReactMethod
public void reloadUpdate(ReadableMap options) {
final String hash = options.getString("hash") == null ?
options.getString("hashName") : options.getString("hash");
final String hash = options.getString("hash");
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
@@ -218,8 +211,7 @@ public class UpdateModule extends ReactContextBaseJavaModule {
@ReactMethod
public void setNeedUpdate(ReadableMap options) {
final String hash = options.getString("hash") == null ?
options.getString("hashName") : options.getString("hash");
final String hash = options.getString("hash");
UiThreadUtil.runOnUiThread(new Runnable() {
@Override

View File

@@ -120,6 +120,7 @@ RCT_EXPORT_MODULE(RCTPushy);
NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
NSString *lastVersion = pushyInfo[paramLastVersion];
NSString *curVersion = pushyInfo[paramCurrentVersion];
NSString *curPackageVersion = [RCTPushy packageVersion];
if (lastVersion.length) {
// roll back to last version
@@ -133,7 +134,7 @@ RCT_EXPORT_MODULE(RCTPushy);
// roll back to bundle
[defaults setObject:nil forKey:keyPushyInfo];
}
[defaults setObject:@(YES) forKey:keyRolledBackMarked];
[defaults setObject:curVersion forKey:keyRolledBackMarked];
[defaults synchronize];
return lastVersion;
}
@@ -151,7 +152,7 @@ RCT_EXPORT_MODULE(RCTPushy);
ret[@"downloadRootDir"] = [RCTPushy downloadDir];
ret[@"packageVersion"] = [RCTPushy packageVersion];
ret[@"buildTime"] = [RCTPushy buildTime];
ret[@"isRolledBack"] = [defaults objectForKey:keyRolledBackMarked];
ret[@"rolledBackVersion"] = [defaults objectForKey:keyRolledBackMarked];
ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked];
ret[@"blockUpdate"] = [defaults objectForKey:keyBlockUpdate];
ret[@"uuid"] = [defaults objectForKey:keyUuid];
@@ -159,12 +160,12 @@ RCT_EXPORT_MODULE(RCTPushy);
ret[@"currentVersion"] = [pushyInfo objectForKey:paramCurrentVersion];
// clear isFirstTimemarked
if ([[defaults objectForKey:keyFirstLoadMarked] boolValue]) {
if (ret[@"isFirstTime"]) {
[defaults setObject:nil forKey:keyFirstLoadMarked];
}
// clear rolledbackmark
if ([[defaults objectForKey:keyRolledBackMarked] boolValue]) {
if (ret[@"rolledBackVersion"] != nil) {
[defaults setObject:nil forKey:keyRolledBackMarked];
[self clearInvalidFiles];
}
@@ -268,9 +269,7 @@ RCT_EXPORT_METHOD(downloadPatchFromPpk:(NSDictionary *)options
RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options)
{
NSString *hash = options[@"hash"];
if (hash.length <= 0) {
hash = options[@"hashName"];
}
if (hash.length) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *lastVersion = nil;
@@ -294,9 +293,7 @@ RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options)
RCT_EXPORT_METHOD(reloadUpdate:(NSDictionary *)options)
{
NSString *hash = options[@"hash"];
if (hash.length <= 0) {
hash = options[@"hashName"];
}
if (hash.length) {
[self setNeedUpdate:options];
@@ -359,9 +356,7 @@ RCT_EXPORT_METHOD(markSuccess)
{
NSString *updateUrl = [RCTConvert NSString:options[@"updateUrl"]];
NSString *hash = [RCTConvert NSString:options[@"hash"]];
if (hash.length <= 0) {
hash = [RCTConvert NSString:options[@"hashName"]];;
}
if (updateUrl.length <= 0 || hash.length <= 0) {
callback([self errorWithMessage:ERROR_OPTIONS]);
return;

View File

@@ -76,6 +76,10 @@ export function getCheckUrl(APPKEY, endpoint = currentEndpoint) {
return `${endpoint}/checkUpdate/${APPKEY}`;
}
export function getReportUrl(endpoint = currentEndpoint) {
return `${endpoint}/report`;
}
export function setCustomEndpoints({ main, backups, backupQueryUrl }) {
currentEndpoint = main;
backupEndpointsQueryUrl = null;

View File

@@ -2,6 +2,7 @@ import {
tryBackupEndpoints,
getCheckUrl,
setCustomEndpoints,
getReportUrl,
} from './endpoint';
import {
NativeEventEmitter,
@@ -25,7 +26,9 @@ export const downloadRootDir = Pushy.downloadRootDir;
export const packageVersion = Pushy.packageVersion;
export const currentVersion = Pushy.currentVersion;
export const isFirstTime = Pushy.isFirstTime;
export const isRolledBack = Pushy.isRolledBack;
const rolledBackVersion = Pushy.rolledBackVersion;
export const isRolledBack = typeof rolledBackVersion === 'string';
export const buildTime = Pushy.buildTime;
let blockUpdate = Pushy.blockUpdate;
let uuid = Pushy.uuid;
@@ -45,7 +48,7 @@ async function getLocalHashInfo(hash) {
}
export async function getCurrentVersionInfo() {
return currentVersion ? await getLocalHashInfo(currentVersion) || {} : {};
return currentVersion ? (await getLocalHashInfo(currentVersion)) || {} : {};
}
const eventEmitter = new NativeEventEmitter(Pushy);
@@ -59,30 +62,29 @@ function logger(text) {
console.log(`Pushy: ${text}`);
}
function report(hash, type) {
logger(type);
fetch(getReportUrl(), {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
hash,
type,
cInfo,
packageVersion,
buildTime,
}),
}).catch((_e) => {});
}
logger('uuid: ' + uuid);
/*
Return json:
Package expired:
{
expired: true,
downloadUrl: 'http://appstore/downloadUrl',
if (isRolledBack) {
report(rolledBackVersion, 'rollback');
}
Package is up to date:
{
upToDate: true,
}
There is available update:
{
update: true,
name: '1.0.3-rc',
hash: 'hash',
description: '添加聊天功能\n修复商城页面BUG',
metaInfo: '{"silent":true}',
pdiffUrl: 'http://update-packages.reactnative.cn/hash',
diffUrl: 'http://update-packages.reactnative.cn/hash',
}
*/
export const cInfo = {
pushy: require('../package.json').version,
@@ -173,6 +175,10 @@ export async function downloadUpdate(options, eventListeners) {
if (!options.update) {
return;
}
if (rolledBackVersion === options.hash) {
logger(`rolledback hash ${rolledBackVersion}, ignored`);
return;
}
if (downloadedHash === options.hash) {
logger(`duplicated downloaded hash ${downloadedHash}, ignored`);
return;
@@ -212,19 +218,30 @@ export async function downloadUpdate(options, eventListeners) {
originHash: currentVersion,
});
} catch (e) {
logger(e.message);
logger('diff error, try pdiff');
logger(`diff error: ${e.message}, try pdiff`);
try {
await Pushy.downloadPatchFromPackage({
updateUrl: options.pdiffUrl,
hash: options.hash,
});
} catch (e) {
progressHandler && progressHandler.remove();
report(options.hash, 'error');
throw e;
}
}
} else if (options.pdiffUrl) {
logger('downloading pdiff');
try {
await Pushy.downloadPatchFromPackage({
updateUrl: options.pdiffUrl,
hash: options.hash,
});
} catch (e) {
progressHandler && progressHandler.remove();
report(options.hash, 'error');
throw e;
}
} else if (options.pdiffUrl) {
logger('downloading pdiff');
await Pushy.downloadPatchFromPackage({
updateUrl: options.pdiffUrl,
hash: options.hash,
});
}
setLocalHashInfo(options.hash, {
name: options.name,
@@ -251,20 +268,23 @@ function assertHash(hash) {
return;
}
readyHash = hash;
return true;
}
export function switchVersion(hash) {
assertRelease();
assertHash(hash);
logger('switchVersion: ' + hash);
Pushy.reloadUpdate({ hash });
if (assertHash(hash)) {
logger('switchVersion: ' + hash);
Pushy.reloadUpdate({ hash });
}
}
export function switchVersionLater(hash) {
assertRelease();
assertHash(hash);
logger('switchVersionLater: ' + hash);
Pushy.setNeedUpdate({ hash });
if (assertHash(hash)) {
logger('switchVersionLater: ' + hash);
Pushy.setNeedUpdate({ hash });
}
}
let marked = false;
@@ -275,8 +295,8 @@ export function markSuccess() {
return;
}
marked = true;
logger('markSuccess');
Pushy.markSuccess();
report(currentVersion, 'success');
}
export async function downloadAndInstallApk({ url, onDownloadProgress }) {

View File

@@ -36,12 +36,15 @@ export function simpleUpdate(WrappedComponent) {
this.checkUpdate();
}
componentWillUnmount() {
this.stateListener.remove();
this.stateListener && this.stateListener.remove();
}
doUpdate = async (info) => {
try {
const hash = await downloadUpdate(info);
this.stateListener.remove();
if (!hash) {
return;
}
this.stateListener && this.stateListener.remove();
Alert.alert('提示', '下载完毕,是否立即更新?', [
{
text: '以后再说',
@@ -91,7 +94,7 @@ export function simpleUpdate(WrappedComponent) {
},
},
]);
} else {
} else if (info.update) {
Alert.alert(
'提示',
'检查到新的版本' + info.name + ',是否下载?\n' + info.description,

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "7.0.0",
"version": "7.3.8",
"description": "react-native hot update",
"main": "lib/index.js",
"scripts": {
@@ -28,6 +28,6 @@
},
"homepage": "https://github.com/reactnativecn/react-native-pushy#readme",
"dependencies": {
"nanoid": "^3.1.28"
"nanoid": "^3.1.30"
}
}