Skip to content

Commit

Permalink
v10.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylqm committed Apr 22, 2024
1 parent ad9b077 commit 5996a7a
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
13 changes: 0 additions & 13 deletions src/client.js

This file was deleted.

19 changes: 13 additions & 6 deletions src/client.native.ts → src/client.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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: '',
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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,
);
Expand Down
20 changes: 17 additions & 3 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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模块无法加载,请对照安装文档检查配置。');
Expand Down
3 changes: 0 additions & 3 deletions src/index.native.ts

This file was deleted.

File renamed without changes.
2 changes: 0 additions & 2 deletions src/provider.jsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/provider.native.tsx → src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Platform,
Linking,
} from 'react-native';
import { Pushy } from './client.native';
import { Pushy } from './client';
import {
currentVersion,
isFirstTime,
Expand Down
18 changes: 11 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand Down

0 comments on commit 5996a7a

Please sign in to comment.