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

Compare commits

..

9 Commits

Author SHA1 Message Date
sunnylqm
7b9a24168a v9.0.3 2023-09-06 23:18:07 +08:00
sunnylqm
c6354bbedc fix: return type 2023-09-06 23:16:42 +08:00
sunnylqm
b53878c291 chore: cleanup 2023-09-06 22:56:41 +08:00
sunnylqm
ab01312f8d v9.0.2 2023-09-06 22:53:54 +08:00
sunnylqm
44784b6d3e feat: return cached result 2023-09-06 11:20:31 +08:00
sunnylqm
30c21fed91 v9.0.1 2023-09-05 22:50:53 +08:00
sunnylqm
15af7802ad fix: type 2023-09-05 22:47:47 +08:00
sunnylqm
8bed6ef979 chore: cleanup 2023-09-05 22:01:13 +08:00
Sunny Luo
7d03dc24b7 Update README.md 2023-09-02 23:02:15 +08:00
4 changed files with 26 additions and 16 deletions

View File

@@ -10,7 +10,7 @@
1. 基于阿里云高速 CDN 分发,对比其他服务器在国外的热更新服务,分发更稳定,更新成功率极高。
2. 基于 bsdiff/hdiff 算法创建的**超小更新包**,通常版本迭代后在几十 KB 级别(其他全量热更新服务所需流量通常在几十 MB 级别)。
3. 始终跟进 RN 最新正式版本,第一时间提供支持。支持 hermes 字节码格式。(暂不支持新架构,会待其相对稳定后跟进)
3. 始终跟进 RN 最新正式版本,第一时间提供支持。支持 hermes 字节码格式。支持新架构
4. 跨越多个版本进行更新时,只需要下载**一个更新包**,不需要逐版本依次更新。
5. 命令行工具 & 网页双端管理,版本发布过程简单便捷,完全可以集成 CI。
6. 支持崩溃回滚,安全可靠。

View File

@@ -10,6 +10,7 @@ import {
PermissionsAndroid,
} from 'react-native';
import {
CheckResult,
EventType,
ProgressData,
UpdateAvailableResult,
@@ -125,30 +126,29 @@ export const cInfo = {
};
function assertRelease() {
// @ts-expect-error
if (__DEV__) {
throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
}
}
let checkingThrottling = false;
let lastChecking = Date.now();
let lastResult: CheckResult = {};
export async function checkUpdate(APPKEY: string, isRetry?: boolean) {
assertRelease();
if (checkingThrottling) {
logger('repeated checking, ignored');
return;
const now = Date.now();
if (lastResult && now - lastChecking < 1000 * 60) {
// logger('repeated checking, ignored');
return lastResult;
}
checkingThrottling = true;
setTimeout(() => {
checkingThrottling = false;
}, 3000);
lastChecking = now;
if (blockUpdate && blockUpdate.until > Date.now() / 1000) {
return report({
report({
type: 'errorChecking',
message: `热更新已暂停,原因:${blockUpdate.reason}。请在"${new Date(
blockUpdate.until * 1000,
).toLocaleString()}"之后重试。`,
});
return lastResult;
}
report({ type: 'checking' });
let resp;
@@ -168,19 +168,28 @@ export async function checkUpdate(APPKEY: string, isRetry?: boolean) {
});
} catch (e) {
if (isRetry) {
return report({
report({
type: 'errorChecking',
message: '无法连接更新服务器,请检查网络连接后重试',
});
return lastResult;
}
await tryBackupEndpoints();
return checkUpdate(APPKEY, true);
}
const result = await resp.json();
const result: CheckResult = await resp.json();
lastResult = result;
// @ts-ignore
checkOperation(result.op);
if (resp.status !== 200) {
return report({ type: 'errorChecking', message: result.message });
report({
type: 'errorChecking',
//@ts-ignore
message: result.message,
});
return lastResult;
}
return result;

View File

@@ -26,7 +26,8 @@ export interface UpdateAvailableResult {
export type CheckResult =
| ExpiredResult
| UpTodateResult
| UpdateAvailableResult;
| UpdateAvailableResult
| {};
export interface ProgressData {
hash: string;

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "9.0.0",
"version": "9.0.3",
"description": "react-native hot update",
"main": "lib/index.ts",
"scripts": {