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",
"version": "10.9.0",
"version": "10.10.0",
"description": "react-native hot update",
"main": "src/index",
"scripts": {

View File

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

View File

@ -19,7 +19,7 @@ import {
packageVersion,
getCurrentVersionInfo,
} from './core';
import { CheckResult, ProgressData } from './type';
import { CheckResult, ProgressData, PushyTestPayload } from './type';
import { PushyContext } from './context';
export const PushyProvider = ({
@ -262,6 +262,25 @@ export const PushyProvider = ({
};
}, [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 (
<PushyContext.Provider
value={{
@ -279,6 +298,7 @@ export const PushyProvider = ({
progress,
downloadAndInstallApk,
getCurrentVersionInfo,
parseTestPayload,
}}>
{children}
</PushyContext.Provider>

View File

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