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

fix: proguard

This commit is contained in:
sunnylqm
2023-09-24 21:11:29 +08:00
parent 6abc960dac
commit 73c3dc538c
2 changed files with 65 additions and 43 deletions

View File

@@ -1,2 +1,3 @@
-keepnames class cn.reactnative.modules.update.DownloadTask { *; }
-keepnames class cn.reactnative.modules.update.UpdateModule { *; }
-keepnames class com.facebook.react.ReactInstanceManager { *; }

View File

@@ -58,34 +58,42 @@ if (!uuid) {
Pushy.setUuid(uuid);
}
function logger(text) {
console.log(`Pushy: ${text}`);
function logger(...args) {
console.log('Pushy: ', ...args);
}
function report(hash, type) {
logger(type);
fetch(getReportUrl(), {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
hash,
type,
const noop = () => {};
let reporter = noop;
export function onEvents(customReporter) {
reporter = customReporter;
if (isRolledBack) {
report({
type: 'rollback',
data: {
rolledBackVersion,
},
});
}
}
function report({ type, message = '', data = {} }) {
logger(type + ' ' + message);
reporter({
type,
data: {
currentVersion,
cInfo,
packageVersion,
buildTime,
}),
}).catch((_e) => {});
message,
...data,
},
});
}
logger('uuid: ' + uuid);
if (isRolledBack) {
report(rolledBackVersion, 'rollback');
}
export const cInfo = {
pushy: require('../package.json').version,
rn: RNVersion,
@@ -99,28 +107,30 @@ function assertRelease() {
}
}
let checkingThrottling = false;
let lastChecking;
const empty = {};
let lastResult;
export async function checkUpdate(APPKEY, isRetry) {
assertRelease();
if (checkingThrottling) {
logger('repeated checking, ignored');
return;
}
checkingThrottling = true;
setTimeout(() => {
checkingThrottling = false;
}, 3000);
if (blockUpdate && blockUpdate.until > Date.now() / 1000) {
throw new Error(
`热更新已暂停,原因:${blockUpdate.reason}。请在"${new Date(
blockUpdate.until * 1000,
).toLocaleString()}"之后重试。`,
);
}
if (typeof APPKEY !== 'string') {
throw new Error('未检查到合法的APPKEY请查看update.json文件是否正确生成');
}
logger('checking update');
assertRelease();
const now = Date.now();
if (lastResult && lastChecking && now - lastChecking < 1000 * 60) {
// logger('repeated checking, ignored');
return lastResult;
}
lastChecking = now;
if (blockUpdate && blockUpdate.until > Date.now() / 1000) {
report({
type: 'errorChecking',
message: `热更新已暂停,原因:${blockUpdate.reason}。请在"${new Date(
blockUpdate.until * 1000,
).toLocaleString()}"之后重试。`,
});
return lastResult || empty;
}
report({ type: 'checking' });
let resp;
try {
resp = await fetch(getCheckUrl(APPKEY), {
@@ -138,16 +148,25 @@ export async function checkUpdate(APPKEY, isRetry) {
});
} catch (e) {
if (isRetry) {
throw new Error('无法连接更新服务器,请检查网络连接后重试');
report({
type: 'errorChecking',
message: '无法连接更新服务器,请检查网络连接后重试',
});
return lastResult || empty;
}
await tryBackupEndpoints();
return checkUpdate(APPKEY, true);
}
const result = await resp.json();
lastResult = result;
checkOperation(result.op);
if (resp.status !== 200) {
throw new Error(result.message);
report({
type: 'errorChecking',
message: result.message,
});
}
return result;
@@ -206,6 +225,7 @@ export async function downloadUpdate(options, eventListeners) {
}
}
let succeeded = false;
report({ type: 'downloading' });
if (options.diffUrl) {
logger('downloading diff');
try {
@@ -245,8 +265,7 @@ export async function downloadUpdate(options, eventListeners) {
}
progressHandler && progressHandler.remove();
if (!succeeded) {
report(options.hash, 'error');
throw new Error('all update attempts failed');
return report({ type: 'errorUpdate', data: { newVersion: options.hash } });
}
setLocalHashInfo(options.hash, {
name: options.name,
@@ -305,10 +324,10 @@ export async function downloadAndInstallApk({ url, onDownloadProgress }) {
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
);
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
return;
return report({ type: 'rejectStoragePermission' });
}
} catch (err) {
console.warn(err);
return report({ type: 'errorStoragePermission' });
}
}
let hash = Date.now().toString();
@@ -327,6 +346,8 @@ export async function downloadAndInstallApk({ url, onDownloadProgress }) {
url,
target: 'update.apk',
hash,
}).catch(() => {
report({ type: 'errowDownloadAndInstallApk' });
});
progressHandler && progressHandler.remove();
}