v10.5.2
This commit is contained in:
parent
ad9b0778ba
commit
5996a7aa75
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update",
|
"name": "react-native-update",
|
||||||
"version": "10.5.1",
|
"version": "10.5.2",
|
||||||
"description": "react-native hot update",
|
"description": "react-native hot update",
|
||||||
"main": "src/index",
|
"main": "src/index",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -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;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,7 @@
|
|||||||
import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
|
import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
|
||||||
import { log, testUrls } from './utils';
|
import { log, testUrls } from './utils';
|
||||||
import {
|
import { EmitterSubscription, Platform } from 'react-native';
|
||||||
EmitterSubscription,
|
import type { PermissionsAndroidStatic } from 'react-native';
|
||||||
PermissionsAndroid,
|
|
||||||
Platform,
|
|
||||||
} from 'react-native';
|
|
||||||
import {
|
import {
|
||||||
PushyModule,
|
PushyModule,
|
||||||
buildTime,
|
buildTime,
|
||||||
@ -27,6 +24,10 @@ const defaultServer = {
|
|||||||
const empty = {};
|
const empty = {};
|
||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
|
|
||||||
|
if (Platform.OS === 'web') {
|
||||||
|
console.warn('react-native-update 不支持 web 端热更,不会执行操作');
|
||||||
|
}
|
||||||
|
|
||||||
export class Pushy {
|
export class Pushy {
|
||||||
options: PushyOptions = {
|
options: PushyOptions = {
|
||||||
appKey: '',
|
appKey: '',
|
||||||
@ -149,10 +150,14 @@ export class Pushy {
|
|||||||
checkUpdate = async () => {
|
checkUpdate = async () => {
|
||||||
if (__DEV__ && !this.options.debug) {
|
if (__DEV__ && !this.options.debug) {
|
||||||
console.info(
|
console.info(
|
||||||
'您当前处于开发环境且未启用debug,不会进行热更检查。如需在开发环境中调试热更,请在client中设置debug为true',
|
'您当前处于开发环境且未启用 debug,不会进行热更检查。如需在开发环境中调试热更,请在 client 中设置 debug 为 true',
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (Platform.OS === 'web') {
|
||||||
|
console.warn('web 端不支持热更新检查');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (
|
if (
|
||||||
this.lastRespJson &&
|
this.lastRespJson &&
|
||||||
@ -366,6 +371,8 @@ export class Pushy {
|
|||||||
this.report({ type: 'downloadingApk' });
|
this.report({ type: 'downloadingApk' });
|
||||||
if (Platform.Version <= 23) {
|
if (Platform.Version <= 23) {
|
||||||
try {
|
try {
|
||||||
|
const PermissionsAndroid =
|
||||||
|
require('react-native/Libraries/PermissionsAndroid/PermissionsAndroid') as PermissionsAndroidStatic;
|
||||||
const granted = await PermissionsAndroid.request(
|
const granted = await PermissionsAndroid.request(
|
||||||
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
|
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
|
||||||
);
|
);
|
20
src/core.ts
20
src/core.ts
@ -8,9 +8,23 @@ const isTurboModuleEnabled =
|
|||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
global.__turboModuleProxy != null;
|
global.__turboModuleProxy != null;
|
||||||
|
|
||||||
export const PushyModule = isTurboModuleEnabled
|
const noop = () => {};
|
||||||
? require('./NativePushy').default
|
class EmptyModule {
|
||||||
: NativeModules.Pushy;
|
constructor() {
|
||||||
|
return new Proxy(this, {
|
||||||
|
get() {
|
||||||
|
return noop;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PushyModule =
|
||||||
|
Platform.OS === 'web'
|
||||||
|
? new EmptyModule()
|
||||||
|
: isTurboModuleEnabled
|
||||||
|
? require('./NativePushy').default
|
||||||
|
: NativeModules.Pushy;
|
||||||
|
|
||||||
if (!PushyModule) {
|
if (!PushyModule) {
|
||||||
throw new Error('react-native-update模块无法加载,请对照安装文档检查配置。');
|
throw new Error('react-native-update模块无法加载,请对照安装文档检查配置。');
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
export { Pushy } from './client.native';
|
|
||||||
export { PushyContext, usePushy } from './context';
|
|
||||||
export { PushyProvider } from './provider.native';
|
|
@ -1,2 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
export const PushyProvider = ({ children }) => <>{children}</>;
|
|
@ -12,7 +12,7 @@ import {
|
|||||||
Platform,
|
Platform,
|
||||||
Linking,
|
Linking,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { Pushy } from './client.native';
|
import { Pushy } from './client';
|
||||||
import {
|
import {
|
||||||
currentVersion,
|
currentVersion,
|
||||||
isFirstTime,
|
isFirstTime,
|
18
src/utils.ts
18
src/utils.ts
@ -1,14 +1,18 @@
|
|||||||
|
import { Platform } from 'react-native';
|
||||||
export function log(...args: any[]) {
|
export function log(...args: any[]) {
|
||||||
console.log('pushy: ', ...args);
|
console.log('pushy: ', ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ping = async (url: string) =>
|
const ping =
|
||||||
Promise.race([
|
Platform.OS === 'web'
|
||||||
fetch(url, {
|
? () => Promise.resolve(true)
|
||||||
method: 'HEAD',
|
: async (url: string) =>
|
||||||
}).then(({ status }) => status === 200),
|
Promise.race([
|
||||||
new Promise<false>(r => setTimeout(() => r(false), 2000)),
|
fetch(url, {
|
||||||
]);
|
method: 'HEAD',
|
||||||
|
}).then(({ status }) => status === 200),
|
||||||
|
new Promise<false>(r => setTimeout(() => r(false), 2000)),
|
||||||
|
]);
|
||||||
|
|
||||||
const canUseGoogle = ping('https://www.google.com');
|
const canUseGoogle = ping('https://www.google.com');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user