mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-18 00:06:10 +08:00
Compare commits
7 Commits
fix/zipsli
...
v9.2.3
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1614a21968 | ||
![]() |
d7879ac2fe | ||
![]() |
a564770597 | ||
![]() |
7229f8847a | ||
![]() |
1daafb0142 | ||
![]() |
c1679a4cea | ||
![]() |
7ab7dffb0f |
@@ -9,6 +9,19 @@ def isNewArchitectureEnabled() {
|
|||||||
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def supportsNamespace() {
|
||||||
|
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
||||||
|
def major = parsed[0].toInteger()
|
||||||
|
def minor = parsed[1].toInteger()
|
||||||
|
|
||||||
|
// Namespace support was added in 7.3.0
|
||||||
|
if (major == 7 && minor >= 3) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return major >= 8
|
||||||
|
}
|
||||||
|
|
||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
if (isNewArchitectureEnabled()) {
|
if (isNewArchitectureEnabled()) {
|
||||||
apply plugin: 'com.facebook.react'
|
apply plugin: 'com.facebook.react'
|
||||||
@@ -16,6 +29,16 @@ if (isNewArchitectureEnabled()) {
|
|||||||
|
|
||||||
|
|
||||||
android {
|
android {
|
||||||
|
|
||||||
|
if (supportsNamespace()) {
|
||||||
|
namespace "cn.reactnative.modules.update"
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
compileSdkVersion safeExtGet('compileSdkVersion', 28)
|
compileSdkVersion safeExtGet('compileSdkVersion', 28)
|
||||||
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
|
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
|
||||||
|
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="cn.reactnative.modules.update">
|
package="cn.reactnative.modules.update">
|
||||||
<application>
|
<application>
|
||||||
|
14
android/src/main/AndroidManifestNew.xml
Normal file
14
android/src/main/AndroidManifestNew.xml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<application>
|
||||||
|
<meta-data android:name="pushy_build_time" android:value="@string/pushy_build_time" />
|
||||||
|
<provider
|
||||||
|
android:name=".PushyFileProvider"
|
||||||
|
android:authorities="${applicationId}.pushy.fileprovider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/pushy_file_paths" />
|
||||||
|
</provider>
|
||||||
|
</application>
|
||||||
|
</manifest>
|
@@ -57,7 +57,7 @@ public class UpdateModule extends NativeUpdateSpec {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadFullUpdate(ReadableMap options, final Promise promise) {
|
public void downloadFullUpdate(ReadableMap options, final Promise promise) {
|
||||||
UpdateModuleImpl.downloadFullUpdate(this.updateContext,options,promise);
|
UpdateModuleImpl.downloadFullUpdate(this.updateContext,options,promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -349,8 +349,7 @@ RCT_EXPORT_METHOD(reloadUpdate:(NSDictionary *)options
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(markSuccess:
|
RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
|
||||||
resolver:(RCTPromiseResolveBlock)resolve
|
|
||||||
rejecter:(RCTPromiseRejectBlock)reject)
|
rejecter:(RCTPromiseRejectBlock)reject)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@@ -1,13 +1,21 @@
|
|||||||
import { logger } from './utils';
|
import { logger, promiseAny } from './utils';
|
||||||
|
|
||||||
let currentEndpoint = 'https://update.react-native.cn/api';
|
let currentEndpoint = 'https://update.react-native.cn/api';
|
||||||
let backupEndpoints: string[] = ['https://update.reactnative.cn/api'];
|
let backupEndpoints: string[] = [
|
||||||
let backupEndpointsQueryUrl: string | null = null;
|
'https://pushy-koa-qgbgqmcpis.cn-beijing.fcapp.run',
|
||||||
|
'https://update.reactnative.cn/api',
|
||||||
|
];
|
||||||
|
let backupEndpointsQueryUrls = [
|
||||||
|
'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json',
|
||||||
|
'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json',
|
||||||
|
];
|
||||||
|
|
||||||
export async function updateBackupEndpoints() {
|
export async function updateBackupEndpoints() {
|
||||||
if (backupEndpointsQueryUrl) {
|
if (backupEndpointsQueryUrls) {
|
||||||
try {
|
try {
|
||||||
const resp = await fetch(backupEndpointsQueryUrl);
|
const resp = await promiseAny(
|
||||||
|
backupEndpointsQueryUrls.map(queryUrl => fetch(queryUrl)),
|
||||||
|
);
|
||||||
const remoteEndpoints = await resp.json();
|
const remoteEndpoints = await resp.json();
|
||||||
if (Array.isArray(remoteEndpoints)) {
|
if (Array.isArray(remoteEndpoints)) {
|
||||||
backupEndpoints = Array.from(
|
backupEndpoints = Array.from(
|
||||||
@@ -36,18 +44,17 @@ export function getCheckUrl(APPKEY, endpoint = currentEndpoint) {
|
|||||||
export function setCustomEndpoints({
|
export function setCustomEndpoints({
|
||||||
main,
|
main,
|
||||||
backups,
|
backups,
|
||||||
backupQueryUrl,
|
backupQueryUrls,
|
||||||
}: {
|
}: {
|
||||||
main: string;
|
main: string;
|
||||||
backups?: string[];
|
backups?: string[];
|
||||||
backupQueryUrl?: string;
|
backupQueryUrls?: string[];
|
||||||
}) {
|
}) {
|
||||||
currentEndpoint = main;
|
currentEndpoint = main;
|
||||||
backupEndpointsQueryUrl = null;
|
|
||||||
if (Array.isArray(backups) && backups.length > 0) {
|
if (Array.isArray(backups) && backups.length > 0) {
|
||||||
backupEndpoints = backups;
|
backupEndpoints = backups;
|
||||||
}
|
}
|
||||||
if (typeof backupQueryUrl === 'string') {
|
if (Array.isArray(backupQueryUrls) && backupQueryUrls.length > 0) {
|
||||||
backupEndpointsQueryUrl = backupQueryUrl;
|
backupEndpointsQueryUrls = backupQueryUrls;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
65
lib/main.ts
65
lib/main.ts
@@ -16,7 +16,7 @@ import {
|
|||||||
UpdateAvailableResult,
|
UpdateAvailableResult,
|
||||||
UpdateEventsListener,
|
UpdateEventsListener,
|
||||||
} from './type';
|
} from './type';
|
||||||
import { assertRelease, logger } from './utils';
|
import { assertRelease, logger, promiseAny, testUrls } from './utils';
|
||||||
export { setCustomEndpoints };
|
export { setCustomEndpoints };
|
||||||
const {
|
const {
|
||||||
version: v,
|
version: v,
|
||||||
@@ -167,8 +167,8 @@ export async function checkUpdate(APPKEY: string) {
|
|||||||
const backupEndpoints = await updateBackupEndpoints();
|
const backupEndpoints = await updateBackupEndpoints();
|
||||||
if (backupEndpoints) {
|
if (backupEndpoints) {
|
||||||
try {
|
try {
|
||||||
resp = await Promise.race(
|
resp = await promiseAny(
|
||||||
backupEndpoints.map((endpoint) =>
|
backupEndpoints.map(endpoint =>
|
||||||
fetch(getCheckUrl(APPKEY, endpoint), fetchPayload),
|
fetch(getCheckUrl(APPKEY, endpoint), fetchPayload),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -205,7 +205,7 @@ function checkOperation(
|
|||||||
if (!Array.isArray(op)) {
|
if (!Array.isArray(op)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
op.forEach((action) => {
|
op.forEach(action => {
|
||||||
if (action.type === 'block') {
|
if (action.type === 'block') {
|
||||||
blockUpdate = {
|
blockUpdate = {
|
||||||
reason: action.reason,
|
reason: action.reason,
|
||||||
@@ -250,7 +250,7 @@ export async function downloadUpdate(
|
|||||||
const downloadCallback = eventListeners.onDownloadProgress;
|
const downloadCallback = eventListeners.onDownloadProgress;
|
||||||
progressHandler = eventEmitter.addListener(
|
progressHandler = eventEmitter.addListener(
|
||||||
'RCTPushyDownloadProgress',
|
'RCTPushyDownloadProgress',
|
||||||
(progressData) => {
|
progressData => {
|
||||||
if (progressData.hash === options.hash) {
|
if (progressData.hash === options.hash) {
|
||||||
downloadCallback(progressData);
|
downloadCallback(progressData);
|
||||||
}
|
}
|
||||||
@@ -260,11 +260,12 @@ export async function downloadUpdate(
|
|||||||
}
|
}
|
||||||
let succeeded = false;
|
let succeeded = false;
|
||||||
report({ type: 'downloading' });
|
report({ type: 'downloading' });
|
||||||
if (options.diffUrl) {
|
const diffUrl = (await testUrls(options.diffUrls)) || options.diffUrl;
|
||||||
|
if (diffUrl) {
|
||||||
logger('downloading diff');
|
logger('downloading diff');
|
||||||
try {
|
try {
|
||||||
await PushyModule.downloadPatchFromPpk({
|
await PushyModule.downloadPatchFromPpk({
|
||||||
updateUrl: options.diffUrl,
|
updateUrl: diffUrl,
|
||||||
hash: options.hash,
|
hash: options.hash,
|
||||||
originHash: currentVersion,
|
originHash: currentVersion,
|
||||||
});
|
});
|
||||||
@@ -273,28 +274,34 @@ export async function downloadUpdate(
|
|||||||
logger(`diff error: ${e.message}, try pdiff`);
|
logger(`diff error: ${e.message}, try pdiff`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!succeeded && options.pdiffUrl) {
|
if (!succeeded) {
|
||||||
logger('downloading pdiff');
|
const pdiffUrl = (await testUrls(options.pdiffUrls)) || options.pdiffUrl;
|
||||||
try {
|
if (pdiffUrl) {
|
||||||
await PushyModule.downloadPatchFromPackage({
|
logger('downloading pdiff');
|
||||||
updateUrl: options.pdiffUrl,
|
try {
|
||||||
hash: options.hash,
|
await PushyModule.downloadPatchFromPackage({
|
||||||
});
|
updateUrl: pdiffUrl,
|
||||||
succeeded = true;
|
hash: options.hash,
|
||||||
} catch (e) {
|
});
|
||||||
logger(`pdiff error: ${e.message}, try full patch`);
|
succeeded = true;
|
||||||
|
} catch (e) {
|
||||||
|
logger(`pdiff error: ${e.message}, try full patch`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!succeeded && options.updateUrl) {
|
if (!succeeded) {
|
||||||
logger('downloading full patch');
|
const updateUrl = (await testUrls(options.updateUrls)) || options.updateUrl;
|
||||||
try {
|
if (updateUrl) {
|
||||||
await PushyModule.downloadFullUpdate({
|
logger('downloading full patch');
|
||||||
updateUrl: options.updateUrl,
|
try {
|
||||||
hash: options.hash,
|
await PushyModule.downloadFullUpdate({
|
||||||
});
|
updateUrl: updateUrl,
|
||||||
succeeded = true;
|
hash: options.hash,
|
||||||
} catch (e) {
|
});
|
||||||
logger(`full patch error: ${e.message}`);
|
succeeded = true;
|
||||||
|
} catch (e) {
|
||||||
|
logger(`full patch error: ${e.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
progressHandler && progressHandler.remove();
|
progressHandler && progressHandler.remove();
|
||||||
@@ -322,12 +329,10 @@ function assertHash(hash: string) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let applyingUpdate = false;
|
|
||||||
export function switchVersion(hash: string) {
|
export function switchVersion(hash: string) {
|
||||||
assertRelease();
|
assertRelease();
|
||||||
if (assertHash(hash) && !applyingUpdate) {
|
if (assertHash(hash)) {
|
||||||
logger('switchVersion: ' + hash);
|
logger('switchVersion: ' + hash);
|
||||||
applyingUpdate = true;
|
|
||||||
PushyModule.reloadUpdate({ hash });
|
PushyModule.reloadUpdate({ hash });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,8 +19,11 @@ export interface UpdateAvailableResult {
|
|||||||
description: string;
|
description: string;
|
||||||
metaInfo: string;
|
metaInfo: string;
|
||||||
pdiffUrl: string;
|
pdiffUrl: string;
|
||||||
|
pdiffUrls?: string[];
|
||||||
diffUrl?: string;
|
diffUrl?: string;
|
||||||
|
diffUrls?: string[];
|
||||||
updateUrl?: string;
|
updateUrl?: string;
|
||||||
|
updateUrls?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CheckResult =
|
export type CheckResult =
|
||||||
|
37
lib/utils.ts
37
lib/utils.ts
@@ -1,9 +1,46 @@
|
|||||||
|
import { Platform } from 'react-native';
|
||||||
|
|
||||||
export function logger(...args: any[]) {
|
export function logger(...args: any[]) {
|
||||||
console.log('Pushy: ', ...args);
|
console.log('Pushy: ', ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function promiseAny<T>(promises: Promise<T>[]) {
|
||||||
|
return new Promise<T>((resolve, reject) => {
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
promises.forEach(promise => {
|
||||||
|
Promise.resolve(promise)
|
||||||
|
.then(resolve)
|
||||||
|
.catch(() => {
|
||||||
|
count++;
|
||||||
|
if (count === promises.length) {
|
||||||
|
reject(new Error('All promises were rejected'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function assertRelease() {
|
export function assertRelease() {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
|
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)),
|
||||||
|
new Promise(r => setTimeout(() => r(null), 2000)),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const testUrls = async (urls?: string[]) => {
|
||||||
|
if (!urls?.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return promiseAny(urls.map(ping)).catch(() => null);
|
||||||
|
};
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update",
|
"name": "react-native-update",
|
||||||
"version": "9.1.4",
|
"version": "9.2.2",
|
||||||
"description": "react-native hot update",
|
"description": "react-native hot update",
|
||||||
"main": "lib/index.ts",
|
"main": "lib/index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -67,5 +67,6 @@
|
|||||||
"react-native": "^0.72.6",
|
"react-native": "^0.72.6",
|
||||||
"ts-jest": "^29.0.3",
|
"ts-jest": "^29.0.3",
|
||||||
"typescript": "^5.2.2"
|
"typescript": "^5.2.2"
|
||||||
}
|
},
|
||||||
|
"packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user