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

Implement download and install apk

This commit is contained in:
sunnylqm
2020-09-27 22:16:27 +08:00
parent 3c5792423e
commit 17ff366f51
10 changed files with 176 additions and 42 deletions

View File

@@ -143,10 +143,11 @@ export async function downloadUpdate(options, eventListeners) {
if (!options.update) {
return;
}
let progressHandler;
if (eventListeners) {
if (eventListeners.onDownloadProgress) {
const downloadCallback = eventListeners.onDownloadProgress;
eventEmitter.addListener('RCTPushyDownloadProgress', (progressData) => {
progressHandler = eventEmitter.addListener('RCTPushyDownloadProgress', (progressData) => {
if (progressData.hash === options.hash) {
downloadCallback(progressData);
}
@@ -167,7 +168,7 @@ export async function downloadUpdate(options, eventListeners) {
hash: options.hash,
});
}
eventEmitter.removeAllListeners('RCTPushyDownloadProgress');
progressHandler && progressHandler.remove();
return options.hash;
}
@@ -188,3 +189,22 @@ export function markSuccess() {
logger('markSuccess');
Pushy.markSuccess();
}
export async function downloadAndInstallApk({ url, onDownloadProgress }) {
logger('downloadAndInstallApk');
let hash = Date.now().toString();
let progressHandler;
if (onDownloadProgress) {
progressHandler = eventEmitter.addListener('RCTPushyDownloadProgress', (progressData) => {
if (progressData.hash === hash) {
onDownloadProgress(progressData);
}
});
}
await Pushy.downloadAndInstallApk({
url,
target: 'update.apk',
hash,
});
progressHandler && progressHandler.remove();
}