react-native-update 8.3.0 → 8.5.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/lib/index.web.js +1 -1
- package/lib/main.ts +31 -24
- package/lib/simpleUpdate.tsx +4 -4
- package/lib/type.ts +3 -0
- package/lib/utils.ts +23 -0
- package/package.json +1 -1
package/lib/index.web.js
CHANGED
package/lib/main.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
UpdateAvailableResult,
|
|
17
17
|
UpdateEventsListener,
|
|
18
18
|
} from './type';
|
|
19
|
-
import { assertRelease, logger } from './utils';
|
|
19
|
+
import { assertRelease, logger, testUrls } from './utils';
|
|
20
20
|
export { setCustomEndpoints };
|
|
21
21
|
const {
|
|
22
22
|
version: v,
|
|
@@ -73,7 +73,7 @@ if (!uuid) {
|
|
|
73
73
|
const noop = () => {};
|
|
74
74
|
let reporter: UpdateEventsListener = noop;
|
|
75
75
|
|
|
76
|
-
export function
|
|
76
|
+
export function onPushyEvents(customReporter: UpdateEventsListener) {
|
|
77
77
|
reporter = customReporter;
|
|
78
78
|
if (isRolledBack) {
|
|
79
79
|
report({
|
|
@@ -255,11 +255,12 @@ export async function downloadUpdate(
|
|
|
255
255
|
}
|
|
256
256
|
let succeeded = false;
|
|
257
257
|
report({ type: 'downloading' });
|
|
258
|
-
|
|
258
|
+
const diffUrl = (await testUrls(options.diffUrls)) || options.diffUrl;
|
|
259
|
+
if (diffUrl) {
|
|
259
260
|
logger('downloading diff');
|
|
260
261
|
try {
|
|
261
262
|
await PushyModule.downloadPatchFromPpk({
|
|
262
|
-
updateUrl:
|
|
263
|
+
updateUrl: diffUrl,
|
|
263
264
|
hash: options.hash,
|
|
264
265
|
originHash: currentVersion,
|
|
265
266
|
});
|
|
@@ -268,28 +269,34 @@ export async function downloadUpdate(
|
|
|
268
269
|
logger(`diff error: ${e.message}, try pdiff`);
|
|
269
270
|
}
|
|
270
271
|
}
|
|
271
|
-
if (!succeeded
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
272
|
+
if (!succeeded) {
|
|
273
|
+
const pdiffUrl = (await testUrls(options.pdiffUrls)) || options.pdiffUrl;
|
|
274
|
+
if (pdiffUrl) {
|
|
275
|
+
logger('downloading pdiff');
|
|
276
|
+
try {
|
|
277
|
+
await PushyModule.downloadPatchFromPackage({
|
|
278
|
+
updateUrl: pdiffUrl,
|
|
279
|
+
hash: options.hash,
|
|
280
|
+
});
|
|
281
|
+
succeeded = true;
|
|
282
|
+
} catch (e) {
|
|
283
|
+
logger(`pdiff error: ${e.message}, try full patch`);
|
|
284
|
+
}
|
|
281
285
|
}
|
|
282
286
|
}
|
|
283
|
-
if (!succeeded
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
287
|
+
if (!succeeded) {
|
|
288
|
+
const updateUrl = (await testUrls(options.updateUrls)) || options.updateUrl;
|
|
289
|
+
if (updateUrl) {
|
|
290
|
+
logger('downloading full patch');
|
|
291
|
+
try {
|
|
292
|
+
await PushyModule.downloadFullUpdate({
|
|
293
|
+
updateUrl: updateUrl,
|
|
294
|
+
hash: options.hash,
|
|
295
|
+
});
|
|
296
|
+
succeeded = true;
|
|
297
|
+
} catch (e) {
|
|
298
|
+
logger(`full patch error: ${e.message}`);
|
|
299
|
+
}
|
|
293
300
|
}
|
|
294
301
|
}
|
|
295
302
|
progressHandler && progressHandler.remove();
|
package/lib/simpleUpdate.tsx
CHANGED
|
@@ -16,20 +16,20 @@ import {
|
|
|
16
16
|
switchVersionLater,
|
|
17
17
|
markSuccess,
|
|
18
18
|
downloadAndInstallApk,
|
|
19
|
-
|
|
19
|
+
onPushyEvents,
|
|
20
20
|
} from './main';
|
|
21
21
|
import { UpdateEventsListener } from './type';
|
|
22
22
|
|
|
23
23
|
export function simpleUpdate(
|
|
24
24
|
WrappedComponent: ComponentType,
|
|
25
|
-
options: { appKey?: string;
|
|
25
|
+
options: { appKey?: string; onPushyEvents?: UpdateEventsListener } = {},
|
|
26
26
|
) {
|
|
27
|
-
const { appKey,
|
|
27
|
+
const { appKey, onPushyEvents: eventListeners } = options;
|
|
28
28
|
if (!appKey) {
|
|
29
29
|
throw new Error('appKey is required for simpleUpdate()');
|
|
30
30
|
}
|
|
31
31
|
if (typeof eventListeners === 'function') {
|
|
32
|
-
|
|
32
|
+
onPushyEvents(eventListeners);
|
|
33
33
|
}
|
|
34
34
|
return __DEV__
|
|
35
35
|
? WrappedComponent
|
package/lib/type.ts
CHANGED
|
@@ -19,8 +19,11 @@ export interface UpdateAvailableResult {
|
|
|
19
19
|
description: string;
|
|
20
20
|
metaInfo: string;
|
|
21
21
|
pdiffUrl: string;
|
|
22
|
+
pdiffUrls?: string[];
|
|
22
23
|
diffUrl?: string;
|
|
24
|
+
diffUrls?: string[];
|
|
23
25
|
updateUrl?: string;
|
|
26
|
+
updateUrls?: string[];
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
export type CheckResult =
|
package/lib/utils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
|
|
1
3
|
export function logger(...args: any[]) {
|
|
2
4
|
console.log('Pushy: ', ...args);
|
|
3
5
|
}
|
|
@@ -7,3 +9,24 @@ export function assertRelease() {
|
|
|
7
9
|
throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
|
|
8
10
|
}
|
|
9
11
|
}
|
|
12
|
+
|
|
13
|
+
const ping =
|
|
14
|
+
Platform.OS === 'web'
|
|
15
|
+
? Promise.resolve
|
|
16
|
+
: async (url: string) =>
|
|
17
|
+
Promise.race([
|
|
18
|
+
fetch(url, {
|
|
19
|
+
method: 'HEAD',
|
|
20
|
+
})
|
|
21
|
+
.then(({ status }) => (status === 200 ? url : null))
|
|
22
|
+
.catch(() => null),
|
|
23
|
+
new Promise(r => setTimeout(() => r(null), 2000)),
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export const testUrls = async (urls?: string[]) => {
|
|
28
|
+
if (!urls?.length) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return Promise.race(urls.map(ping)).catch(() => null);
|
|
32
|
+
};
|