react-native-update 10.38.4 → 10.38.5

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/harmony/pushy.har CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.38.4",
3
+ "version": "10.38.5",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/client.ts CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  ClientOptions,
23
23
  EventType,
24
24
  ProgressData,
25
+ UpdateCheckState,
25
26
  UpdateServerConfig,
26
27
  } from './type';
27
28
  import {
@@ -207,6 +208,16 @@ export class Pushy {
207
208
  throw e;
208
209
  }
209
210
  };
211
+ notifyAfterCheckUpdate = (state: UpdateCheckState) => {
212
+ const { afterCheckUpdate } = this.options;
213
+ if (!afterCheckUpdate) {
214
+ return;
215
+ }
216
+ // 这里仅做状态通知,不阻塞原有检查流程
217
+ Promise.resolve(afterCheckUpdate(state)).catch((error: any) => {
218
+ log('afterCheckUpdate failed:', error?.message || error);
219
+ });
220
+ };
210
221
  getCheckUrl = (endpoint: string) => {
211
222
  return `${endpoint}/checkUpdate/${this.options.appKey}`;
212
223
  };
@@ -329,9 +340,11 @@ export class Pushy {
329
340
  };
330
341
  checkUpdate = async (extra?: Record<string, any>) => {
331
342
  if (!this.assertDebug('checkUpdate()')) {
343
+ this.notifyAfterCheckUpdate({ status: 'skipped' });
332
344
  return;
333
345
  }
334
346
  if (!assertWeb()) {
347
+ this.notifyAfterCheckUpdate({ status: 'skipped' });
335
348
  return;
336
349
  }
337
350
  if (
@@ -339,6 +352,7 @@ export class Pushy {
339
352
  (await this.options.beforeCheckUpdate()) === false
340
353
  ) {
341
354
  log('beforeCheckUpdate returned false, skipping check');
355
+ this.notifyAfterCheckUpdate({ status: 'skipped' });
342
356
  return;
343
357
  }
344
358
  const now = Date.now();
@@ -347,7 +361,9 @@ export class Pushy {
347
361
  this.lastChecking &&
348
362
  now - this.lastChecking < 1000 * 5
349
363
  ) {
350
- return await this.lastRespJson;
364
+ const result = await this.lastRespJson;
365
+ this.notifyAfterCheckUpdate({ status: 'completed', result });
366
+ return result;
351
367
  }
352
368
  this.lastChecking = now;
353
369
  const fetchBody = {
@@ -387,6 +403,7 @@ export class Pushy {
387
403
 
388
404
  log('checking result:', result);
389
405
 
406
+ this.notifyAfterCheckUpdate({ status: 'completed', result });
390
407
  return result;
391
408
  } catch (e: any) {
392
409
  this.lastRespJson = previousRespJson;
@@ -396,6 +413,7 @@ export class Pushy {
396
413
  type: 'errorChecking',
397
414
  message: errorMessage,
398
415
  });
416
+ this.notifyAfterCheckUpdate({ status: 'error', error: e });
399
417
  this.throwIfEnabled(e);
400
418
  return previousRespJson ? await previousRespJson : emptyObj;
401
419
  }
package/src/provider.tsx CHANGED
@@ -165,6 +165,7 @@ export const UpdateProvider = ({
165
165
  async ({ extra }: { extra?: Partial<{ toHash: string }> } = {}) => {
166
166
  const now = Date.now();
167
167
  if (lastChecking.current && now - lastChecking.current < 1000) {
168
+ client.notifyAfterCheckUpdate({ status: 'skipped' });
168
169
  return;
169
170
  }
170
171
  lastChecking.current = now;
package/src/type.ts CHANGED
@@ -35,6 +35,13 @@ export interface ProgressData {
35
35
  total: number;
36
36
  }
37
37
 
38
+ // 用于描述一次检查结束后的最终状态,便于业务侧感知成功、跳过或失败
39
+ export interface UpdateCheckState {
40
+ status: 'completed' | 'skipped' | 'error';
41
+ result?: CheckResult;
42
+ error?: Error;
43
+ }
44
+
38
45
  export type EventType =
39
46
  | 'rollback'
40
47
  | 'errorChecking'
@@ -98,6 +105,8 @@ export interface ClientOptions {
98
105
  debug?: boolean;
99
106
  throwError?: boolean;
100
107
  beforeCheckUpdate?: () => Promise<boolean> | boolean;
108
+ // 每次检查结束后都会触发,不影响原有检查流程
109
+ afterCheckUpdate?: (state: UpdateCheckState) => Promise<void> | void;
101
110
  beforeDownloadUpdate?: (info: CheckResult) => Promise<boolean> | boolean;
102
111
  afterDownloadUpdate?: (info: CheckResult) => Promise<boolean> | boolean;
103
112
  onPackageExpired?: (info: CheckResult) => Promise<boolean> | boolean;