shop-applet/uni_modules/guyue-updater/updater.js

31 lines
711 B
JavaScript
Raw Normal View History

2023-09-20 18:16:59 +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, version='') => {
plus.runtime.install(filePath, {
force: true
}, () => {
console.log('install success...');
if (restart) {
uni.setStorageSync('wgt_version', version);
plus.runtime.restart();
}
}, (e) => {
console.error('install fail...', e);
});
};