react-native-update 10.3.0 → 10.4.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.
@@ -69,13 +69,6 @@ public class UpdateContext {
69
69
  return context.getString(R.string.pushy_build_time);
70
70
  }
71
71
 
72
- public Map getBlockUpdate() {
73
- return new HashMap<String, Object>() {{
74
- put("until", sp.getInt("blockUntil", 0));
75
- put("reason", sp.getString("blockReason", null));
76
- }};
77
- }
78
-
79
72
  public boolean getIsUsingBundleUrl() {
80
73
  return isUsingBundleUrl;
81
74
  }
@@ -45,7 +45,6 @@ public class UpdateModule extends NativePushySpec {
45
45
  if (rolledBackVersion != null) {
46
46
  updateContext.clearRollbackMark();
47
47
  }
48
- constants.put("blockUpdate", updateContext.getBlockUpdate());
49
48
  constants.put("uuid", updateContext.getKv("uuid"));
50
49
  return constants;
51
50
  }
@@ -59,7 +59,6 @@ public class UpdateModule extends ReactContextBaseJavaModule {
59
59
  if (rolledBackVersion != null) {
60
60
  updateContext.clearRollbackMark();
61
61
  }
62
- constants.put("blockUpdate", updateContext.getBlockUpdate());
63
62
  constants.put("uuid", updateContext.getKv("uuid"));
64
63
  return constants;
65
64
  }
@@ -16,7 +16,6 @@ static NSString *const paramLastVersion = @"lastVersion";
16
16
  static NSString *const paramCurrentVersion = @"currentVersion";
17
17
  static NSString *const paramIsFirstTime = @"isFirstTime";
18
18
  static NSString *const paramIsFirstLoadOk = @"isFirstLoadOK";
19
- static NSString *const keyBlockUpdate = @"REACTNATIVECN_PUSHY_BLOCKUPDATE";
20
19
  static NSString *const keyUuid = @"REACTNATIVECN_PUSHY_UUID";
21
20
  static NSString *const keyHashInfo = @"REACTNATIVECN_PUSHY_HASH_";
22
21
  static NSString *const keyFirstLoadMarked = @"REACTNATIVECN_PUSHY_FIRSTLOADMARKED_KEY";
@@ -157,7 +156,6 @@ RCT_EXPORT_MODULE(RCTPushy);
157
156
  ret[@"buildTime"] = [RCTPushy buildTime];
158
157
  ret[@"rolledBackVersion"] = [defaults objectForKey:keyRolledBackMarked];
159
158
  ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked];
160
- ret[@"blockUpdate"] = [defaults objectForKey:keyBlockUpdate];
161
159
  ret[@"uuid"] = [defaults objectForKey:keyUuid];
162
160
  NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
163
161
  ret[@"currentVersion"] = [pushyInfo objectForKey:paramCurrentVersion];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.3.0",
3
+ "version": "10.4.0",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
package/src/client.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
2
- import { assertRelease, log, testUrls } from './utils';
2
+ import { log, testUrls } from './utils';
3
3
  import {
4
4
  EmitterSubscription,
5
5
  PermissionsAndroid,
@@ -112,8 +112,7 @@ export class Pushy {
112
112
  return true;
113
113
  };
114
114
  markSuccess = () => {
115
- assertRelease();
116
- if (this.marked) {
115
+ if (this.marked || __DEV__) {
117
116
  return;
118
117
  }
119
118
  this.marked = true;
@@ -121,7 +120,12 @@ export class Pushy {
121
120
  this.report({ type: 'markSuccess' });
122
121
  };
123
122
  switchVersion = (hash: string) => {
124
- assertRelease();
123
+ if (__DEV__) {
124
+ console.warn(
125
+ '您调用了switchVersion方法,但是当前是开发环境,不会进行任何操作。',
126
+ );
127
+ return;
128
+ }
125
129
  if (this.assertHash(hash) && !this.applyingUpdate) {
126
130
  log('switchVersion: ' + hash);
127
131
  this.applyingUpdate = true;
@@ -130,14 +134,18 @@ export class Pushy {
130
134
  };
131
135
 
132
136
  switchVersionLater = (hash: string) => {
133
- assertRelease();
137
+ if (__DEV__) {
138
+ console.warn(
139
+ '您调用了switchVersionLater方法,但是当前是开发环境,不会进行任何操作。',
140
+ );
141
+ return;
142
+ }
134
143
  if (this.assertHash(hash)) {
135
144
  log('switchVersionLater: ' + hash);
136
145
  PushyModule.setNeedUpdate({ hash });
137
146
  }
138
147
  };
139
148
  checkUpdate = async () => {
140
- assertRelease();
141
149
  const now = Date.now();
142
150
  if (
143
151
  this.lastRespJson &&
@@ -148,18 +156,22 @@ export class Pushy {
148
156
  }
149
157
  this.lastChecking = now;
150
158
  this.report({ type: 'checking' });
159
+ const fetchBody = {
160
+ packageVersion,
161
+ hash: currentVersion,
162
+ buildTime,
163
+ cInfo,
164
+ };
165
+ if (__DEV__) {
166
+ delete fetchBody.buildTime;
167
+ }
151
168
  const fetchPayload = {
152
169
  method: 'POST',
153
170
  headers: {
154
171
  Accept: 'application/json',
155
172
  'Content-Type': 'application/json',
156
173
  },
157
- body: JSON.stringify({
158
- packageVersion,
159
- hash: currentVersion,
160
- buildTime,
161
- cInfo,
162
- }),
174
+ body: JSON.stringify(fetchBody),
163
175
  };
164
176
  let resp;
165
177
  try {
@@ -225,7 +237,6 @@ export class Pushy {
225
237
  info: CheckResult,
226
238
  onDownloadProgress?: (data: ProgressData) => void,
227
239
  ) => {
228
- assertRelease();
229
240
  const {
230
241
  hash,
231
242
  diffUrl: _diffUrl,
@@ -275,7 +286,11 @@ export class Pushy {
275
286
  });
276
287
  succeeded = true;
277
288
  } catch (e: any) {
278
- log(`diff error: ${e.message}, try pdiff`);
289
+ if (__DEV__) {
290
+ succeeded = true;
291
+ } else {
292
+ log(`diff error: ${e.message}, try pdiff`);
293
+ }
279
294
  }
280
295
  }
281
296
  const pdiffUrl = (await testUrls(pdiffUrls)) || _pdiffUrl;
@@ -288,7 +303,11 @@ export class Pushy {
288
303
  });
289
304
  succeeded = true;
290
305
  } catch (e: any) {
291
- log(`pdiff error: ${e.message}, try full patch`);
306
+ if (__DEV__) {
307
+ succeeded = true;
308
+ } else {
309
+ log(`pdiff error: ${e.message}, try full patch`);
310
+ }
292
311
  }
293
312
  }
294
313
  const updateUrl = (await testUrls(updateUrls)) || _updateUrl;
@@ -301,13 +320,20 @@ export class Pushy {
301
320
  });
302
321
  succeeded = true;
303
322
  } catch (e: any) {
304
- log(`full patch error: ${e.message}`);
323
+ if (__DEV__) {
324
+ succeeded = true;
325
+ } else {
326
+ log(`full patch error: ${e.message}`);
327
+ }
305
328
  }
306
329
  }
307
330
  if (this.progressHandlers[hash]) {
308
331
  this.progressHandlers[hash].remove();
309
332
  delete this.progressHandlers[hash];
310
333
  }
334
+ if (__DEV__) {
335
+ return hash;
336
+ }
311
337
  if (!succeeded) {
312
338
  return this.report({
313
339
  type: 'errorUpdate',
package/src/provider.tsx CHANGED
@@ -124,20 +124,20 @@ export const PushyProvider = ({
124
124
  setUpdateInfo(info);
125
125
  if (info.expired) {
126
126
  const { downloadUrl } = info;
127
- showAlert('提示', '您的应用版本已更新,点击更新下载安装新版本', [
128
- {
129
- text: '更新',
130
- onPress: () => {
131
- if (downloadUrl) {
127
+ if (downloadUrl) {
128
+ showAlert('提示', '您的应用版本已更新,点击更新下载安装新版本', [
129
+ {
130
+ text: '更新',
131
+ onPress: () => {
132
132
  if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) {
133
133
  downloadAndInstallApk(downloadUrl);
134
134
  } else {
135
135
  Linking.openURL(downloadUrl);
136
136
  }
137
- }
137
+ },
138
138
  },
139
- },
140
- ]);
139
+ ]);
140
+ }
141
141
  } else if (info.update) {
142
142
  showAlert(
143
143
  '提示',
package/src/type.ts CHANGED
@@ -70,7 +70,7 @@ export interface PushyOptions {
70
70
  server?: PushyServerConfig;
71
71
  logger?: UpdateEventsLogger;
72
72
  useAlert?: boolean;
73
- strategy?: 'onAppStart' | 'onAppResume' | 'both';
73
+ strategy?: 'onAppStart' | 'onAppResume' | 'both' | null;
74
74
  autoMarkSuccess?: boolean;
75
75
  dismissErrorAfter?: number;
76
76
  }
package/src/utils.ts CHANGED
@@ -2,12 +2,6 @@ export function log(...args: any[]) {
2
2
  console.log('pushy: ', ...args);
3
3
  }
4
4
 
5
- export function assertRelease() {
6
- if (__DEV__) {
7
- throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
8
- }
9
- }
10
-
11
5
  const ping = async (url: string) =>
12
6
  Promise.race([
13
7
  fetch(url, {