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

v10.0.0-beta.2

This commit is contained in:
sunnylqm
2024-01-25 22:07:01 +08:00
parent 296498e20a
commit 05e5c5a1a7
11 changed files with 67 additions and 72 deletions

View File

@@ -154,7 +154,6 @@ export class Pushy {
if (resp.status !== 200) {
report({
type: 'errorChecking',
//@ts-ignore
message: result.message,
});
}
@@ -187,11 +186,11 @@ export class Pushy {
onDownloadProgress?: (data: ProgressData) => void,
) => {
assertRelease();
if (!('update' in info)) {
return;
}
const { hash, diffUrl, pdiffUrl, updateUrl, name, description, metaInfo } =
info;
if (!info.update || !hash) {
return;
}
if (rolledBackVersion === hash) {
log(`rolledback hash ${rolledBackVersion}, ignored`);
return;

13
src/client.web.js Normal file
View File

@@ -0,0 +1,13 @@
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,17 +0,0 @@
import { Fragment } from 'react';
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;
},
});
}
}
export { PushyContext, usePushy } from './context';
export const PushyProvider = Fragment;

View File

@@ -45,19 +45,19 @@ export const PushyProvider = ({
);
const switchVersion = useCallback(() => {
if (updateInfo && 'hash' in updateInfo) {
if (updateInfo && updateInfo.hash) {
client.switchVersion(updateInfo.hash);
}
}, [client, updateInfo]);
const switchVersionLater = useCallback(() => {
if (updateInfo && 'hash' in updateInfo) {
if (updateInfo && updateInfo.hash) {
client.switchVersionLater(updateInfo.hash);
}
}, [client, updateInfo]);
const downloadUpdate = useCallback(async () => {
if (!updateInfo || !('update' in updateInfo)) {
if (!updateInfo || !updateInfo.update) {
return;
}
try {
@@ -98,7 +98,7 @@ export const PushyProvider = ({
return;
}
setUpdateInfo(info);
if ('expired' in info) {
if (info.expired) {
const { downloadUrl } = info;
showAlert('提示', '您的应用版本已更新,点击更新下载安装新版本', [
{
@@ -114,7 +114,7 @@ export const PushyProvider = ({
},
},
]);
} else if ('update' in info) {
} else if (info.update) {
showAlert(
'提示',
'检查到新的版本' + info.name + ',是否下载?\n' + info.description,

2
src/provider.web.js Normal file
View File

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

View File

@@ -1,31 +1,19 @@
export interface ExpiredResult {
expired: true;
downloadUrl: string;
}
export interface UpTodateResult {
upToDate: true;
paused?: 'app' | 'package';
}
export interface UpdateAvailableResult {
upToDate: false;
update: true;
name: string; // version name
hash: string;
description: string;
metaInfo: string;
pdiffUrl: string;
export interface CheckResult {
upToDate?: true;
expired?: true;
downloadUrl?: string;
update?: true;
name?: string; // version name
hash?: string;
description?: string;
metaInfo?: string;
pdiffUrl?: string;
diffUrl?: string;
updateUrl?: string;
paused?: 'app' | 'package';
message?: string;
}
export type CheckResult =
| ExpiredResult
| UpTodateResult
| UpdateAvailableResult
| {};
export interface ProgressData {
hash: string;
received: number;
@@ -59,6 +47,7 @@ export interface EventData {
newVersion?: string;
[key: string]: any;
}
export type UpdateEventsLogger = ({
type,
data,
@@ -72,6 +61,7 @@ export interface PushyServerConfig {
backups?: string[];
queryUrl?: string;
}
export interface PushyOptions {
appKey: string;
server?: PushyServerConfig;