react-native-update 10.13.2 → 10.15.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.
@@ -430,6 +430,9 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
430
430
  if (sub.getName().charAt(0) == '.') {
431
431
  continue;
432
432
  }
433
+ if (isFileUpdatedWithinDays(sub, 7)) {
434
+ continue;
435
+ }
433
436
  if (sub.isFile()) {
434
437
  sub.delete();
435
438
  } else {
@@ -441,6 +444,13 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
441
444
  }
442
445
  }
443
446
 
447
+ private boolean isFileUpdatedWithinDays(File file, int days) {
448
+ long currentTime = System.currentTimeMillis();
449
+ long lastModified = file.lastModified();
450
+ long daysInMillis = days * 24 * 60 * 60 * 1000L;
451
+ return (currentTime - lastModified) < daysInMillis;
452
+ }
453
+
444
454
  @Override
445
455
  protected Void doInBackground(DownloadTaskParams... params) {
446
456
  int taskType = params[0].type;
@@ -536,7 +536,15 @@ RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
536
536
 
537
537
  for(NSString *fileName in list) {
538
538
  if (![fileName isEqualToString:curVersion]) {
539
- [_fileManager removeFile:[downloadDir stringByAppendingPathComponent:fileName] completionHandler:nil];
539
+ NSString *filePath = [downloadDir stringByAppendingPathComponent:fileName];
540
+ NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error];
541
+ if (error) {
542
+ continue;
543
+ }
544
+ NSDate *modificationDate = [attributes fileModificationDate];
545
+ if ([[NSDate date] timeIntervalSinceDate:modificationDate] > 7 * 24 * 60 * 60) {
546
+ [_fileManager removeFile:filePath completionHandler:nil];
547
+ }
540
548
  }
541
549
  }
542
550
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.13.2",
3
+ "version": "10.15.0",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/client.ts CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  packageVersion,
12
12
  rolledBackVersion,
13
13
  setLocalHashInfo,
14
+ isFirstTime,
14
15
  isRolledBack,
15
16
  } from './core';
16
17
 
@@ -118,7 +119,7 @@ export class Pushy {
118
119
  return true;
119
120
  };
120
121
  markSuccess = () => {
121
- if (this.marked || __DEV__) {
122
+ if (this.marked || __DEV__ || !isFirstTime) {
122
123
  return;
123
124
  }
124
125
  this.marked = true;
@@ -186,6 +187,7 @@ export class Pushy {
186
187
  ...extra,
187
188
  };
188
189
  if (__DEV__) {
190
+ // @ts-ignore
189
191
  delete fetchBody.buildTime;
190
192
  }
191
193
  const body = JSON.stringify(fetchBody);
package/src/core.ts CHANGED
@@ -14,26 +14,26 @@ export const PushyModule =
14
14
  : NativeModules.Pushy;
15
15
 
16
16
  if (!PushyModule) {
17
- throw new Error('react-native-update模块无法加载,请对照安装文档检查配置。');
17
+ throw new Error('react-native-update 模块无法加载,请对照安装文档检查配置。');
18
18
  }
19
19
 
20
20
  const PushyConstants = isTurboModuleEnabled
21
21
  ? PushyModule.getConstants()
22
22
  : PushyModule;
23
23
 
24
- export const downloadRootDir = PushyConstants.downloadRootDir;
25
- export const packageVersion = PushyConstants.packageVersion;
26
- export const currentVersion = PushyConstants.currentVersion;
27
- export const isFirstTime = PushyConstants.isFirstTime;
28
- export const rolledBackVersion = PushyConstants.rolledBackVersion;
29
- export const isRolledBack = typeof rolledBackVersion === 'string';
24
+ export const downloadRootDir: string = PushyConstants.downloadRootDir;
25
+ export const packageVersion: string = PushyConstants.packageVersion;
26
+ export const currentVersion: string = PushyConstants.currentVersion;
27
+ export const isFirstTime: boolean = PushyConstants.isFirstTime;
28
+ export const rolledBackVersion: string = PushyConstants.rolledBackVersion;
29
+ export const isRolledBack: boolean = typeof rolledBackVersion === 'string';
30
30
 
31
- export const buildTime = PushyConstants.buildTime;
31
+ export const buildTime: string = PushyConstants.buildTime;
32
32
  let uuid = PushyConstants.uuid;
33
33
 
34
34
  if (Platform.OS === 'android' && !PushyConstants.isUsingBundleUrl) {
35
35
  throw new Error(
36
- 'react-native-update模块无法加载,请对照文档检查Bundle URL的配置',
36
+ 'react-native-update 模块无法加载,请对照文档检查 Bundle URL 的配置',
37
37
  );
38
38
  }
39
39
 
@@ -0,0 +1,77 @@
1
+ /* eslint-disable no-fallthrough */
2
+
3
+ import { cInfo } from './core';
4
+
5
+ /* eslint-disable no-bitwise */
6
+ function murmurhash3_32_gc(key: string, seed = 0) {
7
+ let remainder, bytes, h1, h1b, c1, c2, k1, i;
8
+
9
+ remainder = key.length & 3; // key.length % 4
10
+ bytes = key.length - remainder;
11
+ h1 = seed;
12
+ c1 = 0xcc9e2d51;
13
+ c2 = 0x1b873593;
14
+ i = 0;
15
+
16
+ while (i < bytes) {
17
+ k1 =
18
+ (key.charCodeAt(i) & 0xff) |
19
+ ((key.charCodeAt(++i) & 0xff) << 8) |
20
+ ((key.charCodeAt(++i) & 0xff) << 16) |
21
+ ((key.charCodeAt(++i) & 0xff) << 24);
22
+ ++i;
23
+
24
+ ((k1 & 0xffff) * c1 + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff;
25
+ k1 = (k1 << 15) | (k1 >>> 17);
26
+ k1 =
27
+ ((k1 & 0xffff) * c2 + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff;
28
+
29
+ h1 ^= k1;
30
+ h1 = (h1 << 13) | (h1 >>> 19);
31
+ h1b =
32
+ ((h1 & 0xffff) * 5 + ((((h1 >>> 16) * 5) & 0xffff) << 16)) & 0xffffffff;
33
+ h1 = (h1b & 0xffff) + 0x6b64 + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16);
34
+ }
35
+
36
+ k1 = 0;
37
+
38
+ switch (remainder) {
39
+ case 3:
40
+ k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;
41
+ case 2:
42
+ k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;
43
+ case 1:
44
+ k1 ^= key.charCodeAt(i) & 0xff;
45
+
46
+ k1 =
47
+ ((k1 & 0xffff) * c1 + ((((k1 >>> 16) * c1) & 0xffff) << 16)) &
48
+ 0xffffffff;
49
+ k1 = (k1 << 15) | (k1 >>> 17);
50
+ k1 =
51
+ ((k1 & 0xffff) * c2 + ((((k1 >>> 16) * c2) & 0xffff) << 16)) &
52
+ 0xffffffff;
53
+ h1 ^= k1;
54
+ }
55
+
56
+ h1 ^= key.length;
57
+
58
+ h1 ^= h1 >>> 16;
59
+ h1 =
60
+ ((h1 & 0xffff) * 0x85ebca6b +
61
+ ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) &
62
+ 0xffffffff;
63
+ h1 ^= h1 >>> 13;
64
+ h1 =
65
+ ((h1 & 0xffff) * 0xc2b2ae35 +
66
+ ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16)) &
67
+ 0xffffffff;
68
+ h1 ^= h1 >>> 16;
69
+
70
+ return h1 >>> 0;
71
+ }
72
+
73
+ const intForUUID = murmurhash3_32_gc(cInfo.uuid);
74
+
75
+ export function isInRollout(rollout: number) {
76
+ return intForUUID % 100 < rollout;
77
+ }
package/src/provider.tsx CHANGED
@@ -13,15 +13,12 @@ import {
13
13
  Linking,
14
14
  } from 'react-native';
15
15
  import { Pushy } from './client';
16
- import {
17
- currentVersion,
18
- isFirstTime,
19
- packageVersion,
20
- getCurrentVersionInfo,
21
- } from './core';
16
+ import { currentVersion, packageVersion, getCurrentVersionInfo } from './core';
22
17
  import { CheckResult, ProgressData, PushyTestPayload } from './type';
23
18
  import { PushyContext } from './context';
24
19
  import { URL } from 'react-native-url-polyfill';
20
+ import { isInRollout } from './isInRollout';
21
+ import { log } from './utils';
25
22
 
26
23
  export const PushyProvider = ({
27
24
  client,
@@ -165,6 +162,14 @@ export const PushyProvider = ({
165
162
  if (!info) {
166
163
  return;
167
164
  }
165
+ const rollout = info.config?.rollout?.[packageVersion];
166
+ if (rollout) {
167
+ if (!isInRollout(rollout)) {
168
+ log(`not in ${rollout}% rollout, ignored`);
169
+ return;
170
+ }
171
+ log(`in ${rollout}% rollout, continue`);
172
+ }
168
173
  info.description = info.description ?? '';
169
174
  updateInfoRef.current = info;
170
175
  setUpdateInfo(info);
@@ -236,7 +241,7 @@ export const PushyProvider = ({
236
241
  return;
237
242
  }
238
243
  const { checkStrategy, dismissErrorAfter, autoMarkSuccess } = options;
239
- if (isFirstTime && autoMarkSuccess) {
244
+ if (autoMarkSuccess) {
240
245
  markSuccess();
241
246
  }
242
247
  if (checkStrategy === 'both' || checkStrategy === 'onAppResume') {
package/src/type.ts CHANGED
@@ -7,6 +7,12 @@ export interface CheckResult {
7
7
  hash?: string;
8
8
  description?: string;
9
9
  metaInfo?: string;
10
+ config?: {
11
+ rollout?: {
12
+ [packageVersion: string]: number;
13
+ };
14
+ [key: string]: any;
15
+ };
10
16
  pdiff?: string;
11
17
  diff?: string;
12
18
  full?: string;
@@ -43,7 +49,7 @@ export interface EventData {
43
49
  uuid: string;
44
50
  };
45
51
  packageVersion: string;
46
- buildTime: number;
52
+ buildTime: string;
47
53
  message?: string;
48
54
  rolledBackVersion?: string;
49
55
  newVersion?: string;