mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-10-23 09:38:52 +08:00
Update dependencies in package.json and bun.lock, enhance .gitignore to exclude mcp.json, and refactor provider and utils for improved web support.
This commit is contained in:
@@ -23,7 +23,7 @@ import {
|
||||
import { UpdateContext } from './context';
|
||||
import { URL } from 'react-native-url-polyfill';
|
||||
import { isInRollout } from './isInRollout';
|
||||
import { log } from './utils';
|
||||
import { assertWeb, log } from './utils';
|
||||
|
||||
export const UpdateProvider = ({
|
||||
client,
|
||||
@@ -277,6 +277,9 @@ export const UpdateProvider = ({
|
||||
if (!client.assertDebug('checkUpdate()')) {
|
||||
return;
|
||||
}
|
||||
if (!assertWeb()) {
|
||||
return;
|
||||
}
|
||||
const { checkStrategy, dismissErrorAfter, autoMarkSuccess } = options;
|
||||
if (autoMarkSuccess) {
|
||||
setTimeout(() => {
|
||||
@@ -351,6 +354,9 @@ export const UpdateProvider = ({
|
||||
}, [client]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!assertWeb()) {
|
||||
return;
|
||||
}
|
||||
const parseLinking = (url: string | null) => {
|
||||
if (!url) {
|
||||
return;
|
||||
|
65
src/utils.ts
65
src/utils.ts
@@ -5,6 +5,8 @@ export function log(...args: any[]) {
|
||||
console.log(i18n.t('dev_log_prefix'), ...args);
|
||||
}
|
||||
|
||||
export const isWeb = Platform.OS === 'web';
|
||||
|
||||
export function promiseAny<T>(promises: Promise<T>[]) {
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
let count = 0;
|
||||
@@ -35,38 +37,37 @@ class EmptyModule {
|
||||
}
|
||||
export const emptyModule = new EmptyModule();
|
||||
|
||||
const ping =
|
||||
Platform.OS === 'web'
|
||||
? Promise.resolve
|
||||
: async (url: string) => {
|
||||
let pingFinished = false;
|
||||
return Promise.race([
|
||||
enhancedFetch(url, {
|
||||
method: 'HEAD',
|
||||
const ping = isWeb
|
||||
? Promise.resolve
|
||||
: async (url: string) => {
|
||||
let pingFinished = false;
|
||||
return Promise.race([
|
||||
enhancedFetch(url, {
|
||||
method: 'HEAD',
|
||||
})
|
||||
.then(({ status, statusText, url: finalUrl }) => {
|
||||
pingFinished = true;
|
||||
if (status === 200) {
|
||||
return finalUrl;
|
||||
}
|
||||
log('ping failed', url, status, statusText);
|
||||
throw new Error(i18n.t('error_ping_failed'));
|
||||
})
|
||||
.then(({ status, statusText, url: finalUrl }) => {
|
||||
pingFinished = true;
|
||||
if (status === 200) {
|
||||
return finalUrl;
|
||||
}
|
||||
log('ping failed', url, status, statusText);
|
||||
throw new Error(i18n.t('error_ping_failed'));
|
||||
})
|
||||
.catch(e => {
|
||||
pingFinished = true;
|
||||
log('ping error', url, e);
|
||||
throw e;
|
||||
}),
|
||||
new Promise((_, reject) =>
|
||||
setTimeout(() => {
|
||||
reject(new Error(i18n.t('error_ping_timeout')));
|
||||
if (!pingFinished) {
|
||||
log('ping timeout', url);
|
||||
}
|
||||
}, 5000),
|
||||
),
|
||||
]);
|
||||
};
|
||||
.catch(e => {
|
||||
pingFinished = true;
|
||||
log('ping error', url, e);
|
||||
throw e;
|
||||
}),
|
||||
new Promise((_, reject) =>
|
||||
setTimeout(() => {
|
||||
reject(new Error(i18n.t('error_ping_timeout')));
|
||||
if (!pingFinished) {
|
||||
log('ping timeout', url);
|
||||
}
|
||||
}, 5000),
|
||||
),
|
||||
]);
|
||||
};
|
||||
|
||||
export function joinUrls(paths: string[], fileName?: string) {
|
||||
if (fileName) {
|
||||
@@ -91,7 +92,7 @@ export const testUrls = async (urls?: string[]) => {
|
||||
};
|
||||
|
||||
export const assertWeb = () => {
|
||||
if (Platform.OS === 'web') {
|
||||
if (isWeb) {
|
||||
console.warn(i18n.t('dev_web_not_supported'));
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user