1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-18 00:36:10 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Compare commits

..

2 Commits

Author SHA1 Message Date
sunnylqm
78f33f7e5c v10.13.1 2024-08-26 18:54:05 +08:00
sunnylqm
94d2e18900 v10.13.0 2024-08-26 18:52:44 +08:00
5 changed files with 27 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "react-native-update", "name": "react-native-update",
"version": "10.12.0", "version": "10.13.1",
"description": "react-native hot update", "description": "react-native hot update",
"main": "src/index", "main": "src/index",
"scripts": { "scripts": {

View File

@@ -1,5 +1,5 @@
import { CheckResult, PushyOptions, ProgressData, EventType } from './type'; import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
import { log, testUrls } from './utils'; import { joinUrls, log, testUrls } from './utils';
import { EmitterSubscription, Platform } from 'react-native'; import { EmitterSubscription, Platform } from 'react-native';
import { PermissionsAndroid } from './permissions'; import { PermissionsAndroid } from './permissions';
import { import {
@@ -64,8 +64,7 @@ export class Pushy {
setOptions = (options: Partial<PushyOptions>) => { setOptions = (options: Partial<PushyOptions>) => {
for (const [key, value] of Object.entries(options)) { for (const [key, value] of Object.entries(options)) {
if (value !== undefined) { if (value !== undefined) {
// @ts-expect-error (this.options as any)[key] = value;
this.options[key] = value;
if (key === 'logger') { if (key === 'logger') {
if (isRolledBack) { if (isRolledBack) {
this.report({ this.report({
@@ -272,12 +271,10 @@ export class Pushy {
) => { ) => {
const { const {
hash, hash,
diffUrl: _diffUrl, diff,
diffUrls, pdiff,
pdiffUrl: _pdiffUrl, full,
pdiffUrls, paths = [],
updateUrl: _updateUrl,
updateUrls,
name, name,
description, description,
metaInfo, metaInfo,
@@ -316,7 +313,7 @@ export class Pushy {
let succeeded = ''; let succeeded = '';
this.report({ type: 'downloading' }); this.report({ type: 'downloading' });
let lastError: any; let lastError: any;
const diffUrl = (await testUrls(diffUrls)) || _diffUrl; const diffUrl = await testUrls(joinUrls(paths, diff));
if (diffUrl) { if (diffUrl) {
log('downloading diff'); log('downloading diff');
try { try {
@@ -335,7 +332,7 @@ export class Pushy {
} }
} }
} }
const pdiffUrl = (await testUrls(pdiffUrls)) || _pdiffUrl; const pdiffUrl = await testUrls(joinUrls(paths, pdiff));
if (!succeeded && pdiffUrl) { if (!succeeded && pdiffUrl) {
log('downloading pdiff'); log('downloading pdiff');
try { try {
@@ -353,12 +350,12 @@ export class Pushy {
} }
} }
} }
const updateUrl = (await testUrls(updateUrls)) || _updateUrl; const fullUrl = await testUrls(joinUrls(paths, full));
if (!succeeded && updateUrl) { if (!succeeded && fullUrl) {
log('downloading full patch'); log('downloading full patch');
try { try {
await PushyModule.downloadFullUpdate({ await PushyModule.downloadFullUpdate({
updateUrl: updateUrl, updateUrl: fullUrl,
hash, hash,
}); });
succeeded = 'full'; succeeded = 'full';

View File

@@ -4,9 +4,7 @@ const {
version: v, version: v,
} = require('react-native/Libraries/Core/ReactNativeVersion'); } = require('react-native/Libraries/Core/ReactNativeVersion');
const RNVersion = `${v.major}.${v.minor}.${v.patch}`; const RNVersion = `${v.major}.${v.minor}.${v.patch}`;
const isTurboModuleEnabled = const isTurboModuleEnabled = (global as any).__turboModuleProxy != null;
// @ts-expect-error
global.__turboModuleProxy != null;
export const PushyModule = export const PushyModule =
Platform.OS === 'web' Platform.OS === 'web'

View File

@@ -7,12 +7,10 @@ export interface CheckResult {
hash?: string; hash?: string;
description?: string; description?: string;
metaInfo?: string; metaInfo?: string;
pdiffUrl?: string; pdiff?: string;
pdiffUrls?: string[]; diff?: string;
diffUrl?: string; full?: string;
diffUrls?: string[]; paths?: string[];
updateUrl?: string;
updateUrls?: string[];
paused?: 'app' | 'package'; paused?: 'app' | 'package';
message?: string; message?: string;
} }

View File

@@ -31,9 +31,18 @@ const ping =
const canUseGoogle = ping('https://www.google.com'); const canUseGoogle = ping('https://www.google.com');
export function joinUrls(paths: string[], fileName?: string) {
if (fileName) {
return paths.map(path => 'https://' + path + '/' + fileName);
}
}
export const testUrls = async (urls?: string[]) => { export const testUrls = async (urls?: string[]) => {
if (!urls?.length || (await canUseGoogle)) { if (!urls?.length) {
return null; return null;
} }
if (await canUseGoogle) {
return urls[0];
}
return Promise.race(urls.map(ping)).catch(() => null); return Promise.race(urls.map(ping)).catch(() => null);
}; };