Add report
This commit is contained in:
parent
2bf25f37f0
commit
8db8d2162e
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
54
lib/main.js
54
lib/main.js
@ -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;
|
||||
@ -275,8 +281,8 @@ export function markSuccess() {
|
||||
return;
|
||||
}
|
||||
marked = true;
|
||||
logger('markSuccess');
|
||||
Pushy.markSuccess();
|
||||
report(currentVersion, 'success');
|
||||
}
|
||||
|
||||
export async function downloadAndInstallApk({ url, onDownloadProgress }) {
|
||||
|
Loading…
Reference in New Issue
Block a user