1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
sunnylqm 2024-04-23 00:08:53 +08:00
parent ad9b0778ba
commit 5996a7aa75
No known key found for this signature in database
9 changed files with 43 additions and 36 deletions

View File

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

View File

@ -1,13 +0,0 @@
const noop = () => {};
export class Pushy {
constructor() {
console.warn(
'react-native-update is not supported and will do nothing on web.',
);
return new Proxy(this, {
get() {
return noop;
},
});
}
}

View File

@ -1,10 +1,7 @@
import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
import { log, testUrls } from './utils';
import {
EmitterSubscription,
PermissionsAndroid,
Platform,
} from 'react-native';
import { EmitterSubscription, Platform } from 'react-native';
import type { PermissionsAndroidStatic } from 'react-native';
import {
PushyModule,
buildTime,
@ -27,6 +24,10 @@ const defaultServer = {
const empty = {};
const noop = () => {};
if (Platform.OS === 'web') {
console.warn('react-native-update 不支持 web 端热更,不会执行操作');
}
export class Pushy {
options: PushyOptions = {
appKey: '',
@ -149,10 +150,14 @@ export class Pushy {
checkUpdate = async () => {
if (__DEV__ && !this.options.debug) {
console.info(
'您当前处于开发环境且未启用debug不会进行热更检查。如需在开发环境中调试热更请在client中设置debug为true',
'您当前处于开发环境且未启用 debug不会进行热更检查。如需在开发环境中调试热更请在 client 中设置 debug true',
);
return;
}
if (Platform.OS === 'web') {
console.warn('web 端不支持热更新检查');
return;
}
const now = Date.now();
if (
this.lastRespJson &&
@ -366,6 +371,8 @@ export class Pushy {
this.report({ type: 'downloadingApk' });
if (Platform.Version <= 23) {
try {
const PermissionsAndroid =
require('react-native/Libraries/PermissionsAndroid/PermissionsAndroid') as PermissionsAndroidStatic;
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
);

View File

@ -8,9 +8,23 @@ const isTurboModuleEnabled =
// @ts-expect-error
global.__turboModuleProxy != null;
export const PushyModule = isTurboModuleEnabled
? require('./NativePushy').default
: NativeModules.Pushy;
const noop = () => {};
class EmptyModule {
constructor() {
return new Proxy(this, {
get() {
return noop;
},
});
}
}
export const PushyModule =
Platform.OS === 'web'
? new EmptyModule()
: isTurboModuleEnabled
? require('./NativePushy').default
: NativeModules.Pushy;
if (!PushyModule) {
throw new Error('react-native-update模块无法加载请对照安装文档检查配置。');

View File

@ -1,3 +0,0 @@
export { Pushy } from './client.native';
export { PushyContext, usePushy } from './context';
export { PushyProvider } from './provider.native';

View File

@ -1,2 +0,0 @@
import React from 'react';
export const PushyProvider = ({ children }) => <>{children}</>;

View File

@ -12,7 +12,7 @@ import {
Platform,
Linking,
} from 'react-native';
import { Pushy } from './client.native';
import { Pushy } from './client';
import {
currentVersion,
isFirstTime,

View File

@ -1,14 +1,18 @@
import { Platform } from 'react-native';
export function log(...args: any[]) {
console.log('pushy: ', ...args);
}
const ping = async (url: string) =>
Promise.race([
fetch(url, {
method: 'HEAD',
}).then(({ status }) => status === 200),
new Promise<false>(r => setTimeout(() => r(false), 2000)),
]);
const ping =
Platform.OS === 'web'
? () => Promise.resolve(true)
: async (url: string) =>
Promise.race([
fetch(url, {
method: 'HEAD',
}).then(({ status }) => status === 200),
new Promise<false>(r => setTimeout(() => r(false), 2000)),
]);
const canUseGoogle = ping('https://www.google.com');