mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 12:51:44 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c63e1501fe | ||
![]() |
45bfa2560e | ||
![]() |
ab9c40bf2e | ||
![]() |
d184beabaf | ||
![]() |
68a6235145 | ||
![]() |
a98a48d665 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "10.1.0",
|
||||
"version": "10.1.3",
|
||||
"description": "react-native hot update",
|
||||
"main": "src/index.ts",
|
||||
"scripts": {
|
||||
|
@@ -2,29 +2,35 @@ import { createContext, useContext } from 'react';
|
||||
import { CheckResult, ProgressData } from './type';
|
||||
import { Pushy } from './client';
|
||||
|
||||
const empty = {};
|
||||
const noop = () => {};
|
||||
const asyncNoop = () => Promise.resolve();
|
||||
|
||||
export const defaultContext = {
|
||||
checkUpdate: () => Promise.resolve(empty),
|
||||
checkUpdate: asyncNoop,
|
||||
switchVersion: noop,
|
||||
switchVersionLater: noop,
|
||||
markSuccess: noop,
|
||||
dismissError: noop,
|
||||
downloadUpdate: noop,
|
||||
downloadAndInstallApk: noop,
|
||||
downloadUpdate: asyncNoop,
|
||||
downloadAndInstallApk: asyncNoop,
|
||||
getCurrentVersionInfo: () => Promise.resolve({}),
|
||||
currentHash: '',
|
||||
packageVersion: '',
|
||||
};
|
||||
|
||||
export const PushyContext = createContext<{
|
||||
checkUpdate: () => void;
|
||||
checkUpdate: () => Promise<void>;
|
||||
switchVersion: () => void;
|
||||
switchVersionLater: () => void;
|
||||
markSuccess: () => void;
|
||||
dismissError: () => void;
|
||||
downloadUpdate: () => void;
|
||||
downloadAndInstallApk: (url: string) => void;
|
||||
downloadUpdate: () => Promise<void>;
|
||||
downloadAndInstallApk: (url: string) => Promise<void>;
|
||||
getCurrentVersionInfo: () => Promise<{
|
||||
name?: string;
|
||||
description?: string;
|
||||
metaInfo?: string;
|
||||
}>;
|
||||
currentHash: string;
|
||||
packageVersion: string;
|
||||
client?: Pushy;
|
||||
|
@@ -13,7 +13,12 @@ import {
|
||||
Linking,
|
||||
} from 'react-native';
|
||||
import { Pushy } from './client';
|
||||
import { currentVersion, isFirstTime, packageVersion } from './core';
|
||||
import {
|
||||
currentVersion,
|
||||
isFirstTime,
|
||||
packageVersion,
|
||||
getCurrentVersionInfo,
|
||||
} from './core';
|
||||
import { CheckResult, ProgressData } from './type';
|
||||
import { PushyContext } from './context';
|
||||
|
||||
@@ -88,9 +93,9 @@ export const PushyProvider = ({
|
||||
}, [client, showAlert, updateInfo]);
|
||||
|
||||
const downloadAndInstallApk = useCallback(
|
||||
(downloadUrl: string) => {
|
||||
async (downloadUrl: string) => {
|
||||
if (Platform.OS === 'android' && downloadUrl) {
|
||||
client.downloadAndInstallApk(downloadUrl, setProgress);
|
||||
await client.downloadAndInstallApk(downloadUrl, setProgress);
|
||||
}
|
||||
},
|
||||
[client],
|
||||
@@ -188,6 +193,7 @@ export const PushyProvider = ({
|
||||
currentHash: currentVersion,
|
||||
progress,
|
||||
downloadAndInstallApk,
|
||||
getCurrentVersionInfo,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
Reference in New Issue
Block a user