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

Compare commits

...

4 Commits

Author SHA1 Message Date
sunnylqm
b66b4dea06 v10.5.2 2024-04-23 00:08:53 +08:00
sunnylqm
ad9b0778ba v10.5.1 2024-04-22 23:15:34 +08:00
sunnylqm
3e60cfd80f v10.5.0 2024-04-22 23:11:07 +08:00
sunnylqm
782b0e5227 v10.4.2 2024-04-22 09:57:53 +08:00
7 changed files with 47 additions and 35 deletions

View File

@@ -1,8 +1,8 @@
{
"name": "react-native-update",
"version": "10.4.1",
"version": "10.5.2",
"description": "react-native hot update",
"main": "src/index.ts",
"main": "src/index",
"scripts": {
"prepack": "yarn submodule && yarn lint",
"lint": "eslint \"src/*.@(ts|tsx|js|jsx)\" && tsc --noEmit",

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中设置debugtrue',
'您当前处于开发环境且未启用 debug不会进行热更检查。如需在开发环境中调试热更请在 client 中设置 debugtrue',
);
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

@@ -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

@@ -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

@@ -159,8 +159,10 @@ export const PushyProvider = ({
const markSuccess = client.markSuccess;
useEffect(() => {
if (__DEV__) {
console.info('检测到在DEV环境不会进行热更新检查');
if (__DEV__ && !options.debug) {
console.info(
'您当前处于开发环境且未启用debug不会进行热更检查。如需在开发环境中调试热更请在client中设置debug为true',
);
return;
}
const { strategy, dismissErrorAfter, autoMarkSuccess } = options;

View File

@@ -1,2 +0,0 @@
import { Fragment } from 'react';
export const PushyProvider = Fragment;

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');