lihaiCenter/uni_modules/guyue-updater/updater.js

30 lines
649 B
JavaScript
Raw Normal View History

2023-10-08 14:17:20 +08:00
export const download = ({ url, onProgress, onSuccess, onFail }) => {
const task = uni.downloadFile({
url,
success(res) {
if (res.statusCode === 200) {
onSuccess && onSuccess(res.tempFilePath);
}
},
fail() {
onFail && onFail();
}
});
task.onProgressUpdate(res => {
onProgress && onProgress(res.progress);
});
};
export const install = (filePath, restart = false) => {
plus.runtime.install(filePath, {
force: true
}, () => {
console.log('install success...');
if (restart) {
plus.runtime.restart();
}
}, (e) => {
console.error('install fail...', e);
});
};