mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-18 00:06:10 +08:00
Implement download and install apk
This commit is contained in:
24
lib/index.js
24
lib/index.js
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user