react-native-update 10.8.0 → 10.9.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.8.0",
3
+ "version": "10.9.0",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/client.ts CHANGED
@@ -150,7 +150,7 @@ export class Pushy {
150
150
  PushyModule.setNeedUpdate({ hash });
151
151
  }
152
152
  };
153
- checkUpdate = async () => {
153
+ checkUpdate = async (extra?: Record<string, any>) => {
154
154
  if (__DEV__ && !this.options.debug) {
155
155
  console.info(
156
156
  '您当前处于开发环境且未启用 debug,不会进行热更检查。如需在开发环境中调试热更,请在 client 中设置 debug 为 true',
@@ -176,6 +176,7 @@ export class Pushy {
176
176
  hash: currentVersion,
177
177
  buildTime,
178
178
  cInfo,
179
+ ...extra,
179
180
  };
180
181
  if (__DEV__) {
181
182
  delete fetchBody.buildTime;
package/src/provider.tsx CHANGED
@@ -145,81 +145,84 @@ export const PushyProvider = ({
145
145
  [client],
146
146
  );
147
147
 
148
- const checkUpdate = useCallback(async () => {
149
- const now = Date.now();
150
- if (lastChecking.current && now - lastChecking.current < 1000) {
151
- return;
152
- }
153
- lastChecking.current = now;
154
- let info: CheckResult;
155
- try {
156
- info = await client.checkUpdate();
157
- } catch (e: any) {
158
- setLastError(e);
159
- alertError('更新检查失败', e.message);
160
- throwErrorIfEnabled(e);
161
- return;
162
- }
163
- if (!info) {
164
- return;
165
- }
166
- updateInfoRef.current = info;
167
- setUpdateInfo(info);
168
- if (info.expired) {
169
- const { downloadUrl } = info;
170
- if (downloadUrl) {
171
- if (options.updateStrategy === 'silentAndNow') {
172
- if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) {
173
- downloadAndInstallApk(downloadUrl);
174
- } else {
175
- Linking.openURL(downloadUrl);
148
+ const checkUpdate = useCallback(
149
+ async (extra?: Record<string, any>) => {
150
+ const now = Date.now();
151
+ if (lastChecking.current && now - lastChecking.current < 1000) {
152
+ return;
153
+ }
154
+ lastChecking.current = now;
155
+ let info: CheckResult;
156
+ try {
157
+ info = await client.checkUpdate(extra);
158
+ } catch (e: any) {
159
+ setLastError(e);
160
+ alertError('更新检查失败', e.message);
161
+ throwErrorIfEnabled(e);
162
+ return;
163
+ }
164
+ if (!info) {
165
+ return;
166
+ }
167
+ updateInfoRef.current = info;
168
+ setUpdateInfo(info);
169
+ if (info.expired) {
170
+ const { downloadUrl } = info;
171
+ if (downloadUrl) {
172
+ if (options.updateStrategy === 'silentAndNow') {
173
+ if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) {
174
+ downloadAndInstallApk(downloadUrl);
175
+ } else {
176
+ Linking.openURL(downloadUrl);
177
+ }
178
+ return;
176
179
  }
177
- return;
180
+ alertUpdate('提示', '您的应用版本已更新,点击更新下载安装新版本', [
181
+ {
182
+ text: '更新',
183
+ onPress: () => {
184
+ if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) {
185
+ downloadAndInstallApk(downloadUrl);
186
+ } else {
187
+ Linking.openURL(downloadUrl);
188
+ }
189
+ },
190
+ },
191
+ ]);
178
192
  }
179
- alertUpdate('提示', '您的应用版本已更新,点击更新下载安装新版本', [
180
- {
181
- text: '更新',
182
- onPress: () => {
183
- if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) {
184
- downloadAndInstallApk(downloadUrl);
185
- } else {
186
- Linking.openURL(downloadUrl);
187
- }
193
+ } else if (info.update) {
194
+ if (
195
+ options.updateStrategy === 'silentAndNow' ||
196
+ options.updateStrategy === 'silentAndLater'
197
+ ) {
198
+ return downloadUpdate(info);
199
+ }
200
+ alertUpdate(
201
+ '提示',
202
+ '检查到新的版本' + info.name + ',是否下载?\n' + info.description,
203
+ [
204
+ { text: '取消', style: 'cancel' },
205
+ {
206
+ text: '确定',
207
+ style: 'default',
208
+ onPress: () => {
209
+ downloadUpdate();
210
+ },
188
211
  },
189
- },
190
- ]);
191
- }
192
- } else if (info.update) {
193
- if (
194
- options.updateStrategy === 'silentAndNow' ||
195
- options.updateStrategy === 'silentAndLater'
196
- ) {
197
- return downloadUpdate(info);
212
+ ],
213
+ );
198
214
  }
199
- alertUpdate(
200
- '提示',
201
- '检查到新的版本' + info.name + ',是否下载?\n' + info.description,
202
- [
203
- { text: '取消', style: 'cancel' },
204
- {
205
- text: '确定',
206
- style: 'default',
207
- onPress: () => {
208
- downloadUpdate();
209
- },
210
- },
211
- ],
212
- );
213
- }
214
- }, [
215
- client,
216
- alertError,
217
- throwErrorIfEnabled,
218
- options.updateStrategy,
219
- alertUpdate,
220
- downloadAndInstallApk,
221
- downloadUpdate,
222
- ]);
215
+ },
216
+ [
217
+ client,
218
+ alertError,
219
+ throwErrorIfEnabled,
220
+ options.updateStrategy,
221
+ alertUpdate,
222
+ downloadAndInstallApk,
223
+ downloadUpdate,
224
+ ],
225
+ );
223
226
 
224
227
  const markSuccess = client.markSuccess;
225
228