1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
sunnylqm 2024-07-25 22:52:18 +08:00
parent 0fdb33ab10
commit 28b8e122af
No known key found for this signature in database
4 changed files with 29 additions and 2 deletions

View File

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

View File

@ -14,6 +14,7 @@ export const defaultContext = {
downloadUpdate: asyncNoop, downloadUpdate: asyncNoop,
downloadAndInstallApk: asyncNoop, downloadAndInstallApk: asyncNoop,
getCurrentVersionInfo: () => Promise.resolve({}), getCurrentVersionInfo: () => Promise.resolve({}),
parseTestPayload: () => Promise.resolve(false),
currentHash: '', currentHash: '',
packageVersion: '', packageVersion: '',
}; };
@ -31,6 +32,7 @@ export const PushyContext = createContext<{
description?: string; description?: string;
metaInfo?: string; metaInfo?: string;
}>; }>;
parseTestPayload: (code: string) => Promise<boolean>;
currentHash: string; currentHash: string;
packageVersion: string; packageVersion: string;
client?: Pushy; client?: Pushy;

View File

@ -19,7 +19,7 @@ import {
packageVersion, packageVersion,
getCurrentVersionInfo, getCurrentVersionInfo,
} from './core'; } from './core';
import { CheckResult, ProgressData } from './type'; import { CheckResult, ProgressData, PushyTestPayload } from './type';
import { PushyContext } from './context'; import { PushyContext } from './context';
export const PushyProvider = ({ export const PushyProvider = ({
@ -262,6 +262,25 @@ export const PushyProvider = ({
}; };
}, [checkUpdate, options, dismissError, markSuccess]); }, [checkUpdate, options, dismissError, markSuccess]);
const parseTestPayload = useCallback(
async (code: string) => {
let payload: PushyTestPayload;
try {
payload = JSON.parse(code);
} catch {
return false;
}
if (payload && payload.type) {
if (payload.type === '__rnPushyVersionHash') {
await checkUpdate({ toHash: payload.data });
return true;
}
}
return false;
},
[checkUpdate],
);
return ( return (
<PushyContext.Provider <PushyContext.Provider
value={{ value={{
@ -279,6 +298,7 @@ export const PushyProvider = ({
progress, progress,
downloadAndInstallApk, downloadAndInstallApk,
getCurrentVersionInfo, getCurrentVersionInfo,
parseTestPayload,
}}> }}>
{children} {children}
</PushyContext.Provider> </PushyContext.Provider>

View File

@ -81,3 +81,8 @@ export interface PushyOptions {
debug?: boolean; debug?: boolean;
throwError?: boolean; throwError?: boolean;
} }
export interface PushyTestPayload {
type: '__rnPushyVersionHash';
data: any;
}