react-native-update 9.0.0 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/main.ts +17 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
1. 基于阿里云高速 CDN 分发,对比其他服务器在国外的热更新服务,分发更稳定,更新成功率极高。
|
|
12
12
|
2. 基于 bsdiff/hdiff 算法创建的**超小更新包**,通常版本迭代后在几十 KB 级别(其他全量热更新服务所需流量通常在几十 MB 级别)。
|
|
13
|
-
3. 始终跟进 RN 最新正式版本,第一时间提供支持。支持 hermes
|
|
13
|
+
3. 始终跟进 RN 最新正式版本,第一时间提供支持。支持 hermes 字节码格式。支持新架构。
|
|
14
14
|
4. 跨越多个版本进行更新时,只需要下载**一个更新包**,不需要逐版本依次更新。
|
|
15
15
|
5. 命令行工具 & 网页双端管理,版本发布过程简单便捷,完全可以集成 CI。
|
|
16
16
|
6. 支持崩溃回滚,安全可靠。
|
package/lib/main.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
PermissionsAndroid,
|
|
11
11
|
} from 'react-native';
|
|
12
12
|
import {
|
|
13
|
+
CheckResult,
|
|
13
14
|
EventType,
|
|
14
15
|
ProgressData,
|
|
15
16
|
UpdateAvailableResult,
|
|
@@ -125,30 +126,28 @@ export const cInfo = {
|
|
|
125
126
|
};
|
|
126
127
|
|
|
127
128
|
function assertRelease() {
|
|
128
|
-
// @ts-expect-error
|
|
129
129
|
if (__DEV__) {
|
|
130
130
|
throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
let
|
|
134
|
+
let lastChecking = Date.now();
|
|
135
135
|
export async function checkUpdate(APPKEY: string, isRetry?: boolean) {
|
|
136
136
|
assertRelease();
|
|
137
|
-
|
|
137
|
+
const now = Date.now();
|
|
138
|
+
if (now - lastChecking < 1000 * 5) {
|
|
138
139
|
logger('repeated checking, ignored');
|
|
139
140
|
return;
|
|
140
141
|
}
|
|
141
|
-
|
|
142
|
-
setTimeout(() => {
|
|
143
|
-
checkingThrottling = false;
|
|
144
|
-
}, 3000);
|
|
142
|
+
lastChecking = now;
|
|
145
143
|
if (blockUpdate && blockUpdate.until > Date.now() / 1000) {
|
|
146
|
-
|
|
144
|
+
report({
|
|
147
145
|
type: 'errorChecking',
|
|
148
146
|
message: `热更新已暂停,原因:${blockUpdate.reason}。请在"${new Date(
|
|
149
147
|
blockUpdate.until * 1000,
|
|
150
148
|
).toLocaleString()}"之后重试。`,
|
|
151
149
|
});
|
|
150
|
+
return;
|
|
152
151
|
}
|
|
153
152
|
report({ type: 'checking' });
|
|
154
153
|
let resp;
|
|
@@ -168,19 +167,26 @@ export async function checkUpdate(APPKEY: string, isRetry?: boolean) {
|
|
|
168
167
|
});
|
|
169
168
|
} catch (e) {
|
|
170
169
|
if (isRetry) {
|
|
171
|
-
|
|
170
|
+
report({
|
|
172
171
|
type: 'errorChecking',
|
|
173
172
|
message: '无法连接更新服务器,请检查网络连接后重试',
|
|
174
173
|
});
|
|
174
|
+
return;
|
|
175
175
|
}
|
|
176
176
|
await tryBackupEndpoints();
|
|
177
177
|
return checkUpdate(APPKEY, true);
|
|
178
178
|
}
|
|
179
|
-
const result = await resp.json();
|
|
179
|
+
const result: CheckResult = await resp.json();
|
|
180
|
+
// @ts-ignore
|
|
180
181
|
checkOperation(result.op);
|
|
181
182
|
|
|
182
183
|
if (resp.status !== 200) {
|
|
183
|
-
|
|
184
|
+
report({
|
|
185
|
+
type: 'errorChecking',
|
|
186
|
+
//@ts-ignore
|
|
187
|
+
message: result.message,
|
|
188
|
+
});
|
|
189
|
+
return;
|
|
184
190
|
}
|
|
185
191
|
|
|
186
192
|
return result;
|