mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-18 00:26:11 +08:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
10ac7073a8 |
@@ -15,4 +15,4 @@ export const downloadAndInstallApk = noop;
|
||||
export const setCustomEndpoints = noop;
|
||||
export const getCurrentVersionInfo = noop;
|
||||
export const simpleUpdate = (app) => app;
|
||||
export const onPushyEvents = noop;
|
||||
export const onEvents = noop;
|
||||
|
55
lib/main.ts
55
lib/main.ts
@@ -16,7 +16,7 @@ import {
|
||||
UpdateAvailableResult,
|
||||
UpdateEventsListener,
|
||||
} from './type';
|
||||
import { assertRelease, logger, testUrls } from './utils';
|
||||
import { assertRelease, logger } from './utils';
|
||||
export { setCustomEndpoints };
|
||||
const {
|
||||
version: v,
|
||||
@@ -73,7 +73,7 @@ if (!uuid) {
|
||||
const noop = () => {};
|
||||
let reporter: UpdateEventsListener = noop;
|
||||
|
||||
export function onPushyEvents(customReporter: UpdateEventsListener) {
|
||||
export function onEvents(customReporter: UpdateEventsListener) {
|
||||
reporter = customReporter;
|
||||
if (isRolledBack) {
|
||||
report({
|
||||
@@ -255,12 +255,11 @@ export async function downloadUpdate(
|
||||
}
|
||||
let succeeded = false;
|
||||
report({ type: 'downloading' });
|
||||
const diffUrl = (await testUrls(options.diffUrls)) || options.diffUrl;
|
||||
if (diffUrl) {
|
||||
if (options.diffUrl) {
|
||||
logger('downloading diff');
|
||||
try {
|
||||
await PushyModule.downloadPatchFromPpk({
|
||||
updateUrl: diffUrl,
|
||||
updateUrl: options.diffUrl,
|
||||
hash: options.hash,
|
||||
originHash: currentVersion,
|
||||
});
|
||||
@@ -269,34 +268,28 @@ export async function downloadUpdate(
|
||||
logger(`diff error: ${e.message}, try pdiff`);
|
||||
}
|
||||
}
|
||||
if (!succeeded) {
|
||||
const pdiffUrl = (await testUrls(options.pdiffUrls)) || options.pdiffUrl;
|
||||
if (pdiffUrl) {
|
||||
logger('downloading pdiff');
|
||||
try {
|
||||
await PushyModule.downloadPatchFromPackage({
|
||||
updateUrl: pdiffUrl,
|
||||
hash: options.hash,
|
||||
});
|
||||
succeeded = true;
|
||||
} catch (e) {
|
||||
logger(`pdiff error: ${e.message}, try full patch`);
|
||||
}
|
||||
if (!succeeded && options.pdiffUrl) {
|
||||
logger('downloading pdiff');
|
||||
try {
|
||||
await PushyModule.downloadPatchFromPackage({
|
||||
updateUrl: options.pdiffUrl,
|
||||
hash: options.hash,
|
||||
});
|
||||
succeeded = true;
|
||||
} catch (e) {
|
||||
logger(`pdiff error: ${e.message}, try full patch`);
|
||||
}
|
||||
}
|
||||
if (!succeeded) {
|
||||
const updateUrl = (await testUrls(options.updateUrls)) || options.updateUrl;
|
||||
if (updateUrl) {
|
||||
logger('downloading full patch');
|
||||
try {
|
||||
await PushyModule.downloadFullUpdate({
|
||||
updateUrl: updateUrl,
|
||||
hash: options.hash,
|
||||
});
|
||||
succeeded = true;
|
||||
} catch (e) {
|
||||
logger(`full patch error: ${e.message}`);
|
||||
}
|
||||
if (!succeeded && options.updateUrl) {
|
||||
logger('downloading full patch');
|
||||
try {
|
||||
await PushyModule.downloadFullUpdate({
|
||||
updateUrl: options.updateUrl,
|
||||
hash: options.hash,
|
||||
});
|
||||
succeeded = true;
|
||||
} catch (e) {
|
||||
logger(`full patch error: ${e.message}`);
|
||||
}
|
||||
}
|
||||
progressHandler && progressHandler.remove();
|
||||
|
@@ -16,20 +16,20 @@ import {
|
||||
switchVersionLater,
|
||||
markSuccess,
|
||||
downloadAndInstallApk,
|
||||
onPushyEvents,
|
||||
onEvents,
|
||||
} from './main';
|
||||
import { UpdateEventsListener } from './type';
|
||||
|
||||
export function simpleUpdate(
|
||||
WrappedComponent: ComponentType,
|
||||
options: { appKey?: string; onPushyEvents?: UpdateEventsListener } = {},
|
||||
options: { appKey?: string; onEvents?: UpdateEventsListener } = {},
|
||||
) {
|
||||
const { appKey, onPushyEvents: eventListeners } = options;
|
||||
const { appKey, onEvents: eventListeners } = options;
|
||||
if (!appKey) {
|
||||
throw new Error('appKey is required for simpleUpdate()');
|
||||
}
|
||||
if (typeof eventListeners === 'function') {
|
||||
onPushyEvents(eventListeners);
|
||||
onEvents(eventListeners);
|
||||
}
|
||||
return __DEV__
|
||||
? WrappedComponent
|
||||
|
@@ -19,11 +19,8 @@ export interface UpdateAvailableResult {
|
||||
description: string;
|
||||
metaInfo: string;
|
||||
pdiffUrl: string;
|
||||
pdiffUrls?: string[];
|
||||
diffUrl?: string;
|
||||
diffUrls?: string[];
|
||||
updateUrl?: string;
|
||||
updateUrls?: string[];
|
||||
}
|
||||
|
||||
export type CheckResult =
|
||||
|
23
lib/utils.ts
23
lib/utils.ts
@@ -1,5 +1,3 @@
|
||||
import { Platform } from "react-native";
|
||||
|
||||
export function logger(...args: any[]) {
|
||||
console.log('Pushy: ', ...args);
|
||||
}
|
||||
@@ -9,24 +7,3 @@ export function assertRelease() {
|
||||
throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
|
||||
}
|
||||
}
|
||||
|
||||
const ping =
|
||||
Platform.OS === 'web'
|
||||
? Promise.resolve
|
||||
: async (url: string) =>
|
||||
Promise.race([
|
||||
fetch(url, {
|
||||
method: 'HEAD',
|
||||
})
|
||||
.then(({ status }) => (status === 200 ? url : null))
|
||||
.catch(() => null),
|
||||
new Promise(r => setTimeout(() => r(null), 2000)),
|
||||
]);
|
||||
|
||||
|
||||
export const testUrls = async (urls?: string[]) => {
|
||||
if (!urls?.length) {
|
||||
return null;
|
||||
}
|
||||
return Promise.race(urls.map(ping)).catch(() => null);
|
||||
};
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "8.5.0",
|
||||
"version": "8.4.0",
|
||||
"description": "react-native hot update",
|
||||
"main": "lib/index.ts",
|
||||
"scripts": {
|
||||
|
Reference in New Issue
Block a user