Skip to content

Commit

Permalink
v10.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylqm committed Jul 25, 2024
1 parent 0fdb33a commit 28b8e12
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 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.9.0",
"version": "10.10.0",
"description": "react-native hot update",
"main": "src/index",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const defaultContext = {
downloadUpdate: asyncNoop,
downloadAndInstallApk: asyncNoop,
getCurrentVersionInfo: () => Promise.resolve({}),
parseTestPayload: () => Promise.resolve(false),
currentHash: '',
packageVersion: '',
};
Expand All @@ -31,6 +32,7 @@ export const PushyContext = createContext<{
description?: string;
metaInfo?: string;
}>;
parseTestPayload: (code: string) => Promise<boolean>;
currentHash: string;
packageVersion: string;
client?: Pushy;
Expand Down
22 changes: 21 additions & 1 deletion src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand Down Expand Up @@ -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={{
Expand All @@ -279,6 +298,7 @@ export const PushyProvider = ({
progress,
downloadAndInstallApk,
getCurrentVersionInfo,
parseTestPayload,
}}>
{children}
</PushyContext.Provider>
Expand Down
5 changes: 5 additions & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,8 @@ export interface PushyOptions {
debug?: boolean;
throwError?: boolean;
}

export interface PushyTestPayload {
type: '__rnPushyVersionHash';
data: any;
}

0 comments on commit 28b8e12

Please sign in to comment.