|
@@ -4,23 +4,20 @@ import { FileOpener } from '@ionic-native/file-opener/ngx';
|
|
|
import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer/ngx';
|
|
|
import { AppVersion } from '@ionic-native/app-version/ngx';
|
|
|
import { File } from '@ionic-native/file/ngx';
|
|
|
-import { AlertController } from '@ionic/angular';
|
|
|
+import { AlertController, LoadingController } from '@ionic/angular';
|
|
|
import { HTTP } from '@ionic-native/http/ngx';
|
|
|
-import { from } from 'rxjs';
|
|
|
-import { finalize } from 'rxjs/operators';
|
|
|
|
|
|
@Injectable({
|
|
|
providedIn: 'root'
|
|
|
})
|
|
|
|
|
|
export class Update {
|
|
|
-
|
|
|
-
|
|
|
constructor(private file: File,
|
|
|
private transfer: FileTransfer,
|
|
|
private nativeHttp: HTTP,
|
|
|
private appVersion: AppVersion,
|
|
|
private fileOpener: FileOpener,
|
|
|
+ private loadingCtrl: LoadingController,
|
|
|
public alertController: AlertController) {
|
|
|
}
|
|
|
|
|
@@ -80,6 +77,12 @@ export class Update {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ setLoadingText(text: string) {
|
|
|
+ const elem = document.querySelector(
|
|
|
+ "div.loading-wrapper div.loading-content");
|
|
|
+ if (elem) elem.innerHTML = text;
|
|
|
+ }
|
|
|
+
|
|
|
async showAlert(version) {
|
|
|
//3.弹窗提示用户是否更新
|
|
|
const alert = await this.alertController.create({
|
|
@@ -106,7 +109,7 @@ export class Update {
|
|
|
}
|
|
|
|
|
|
|
|
|
- downloadApp() {
|
|
|
+ async downloadApp() {
|
|
|
//4.下载apk
|
|
|
const targetUrl = 'http://192.168.20.15:803/SoftUpdate/SgApp/app-debug.apk';
|
|
|
const fileTransfer: FileTransferObject = this.transfer.create();
|
|
@@ -129,16 +132,17 @@ export class Update {
|
|
|
alert(JSON.stringify(error));
|
|
|
});
|
|
|
|
|
|
+ let loading = await this.loadingCtrl.create({
|
|
|
+ message: '下载进度:0%'
|
|
|
+ })
|
|
|
+ await loading.present()
|
|
|
|
|
|
//5、获取下载进度
|
|
|
- var oProgressNum = document.getElementById('progressnum');
|
|
|
- fileTransfer.onProgress((event) => {
|
|
|
+ fileTransfer.onProgress(async (event) => {
|
|
|
let num = Math.ceil(event.loaded / event.total * 100); //转化成1-100的进度
|
|
|
+ this.setLoadingText(`下载进度:${num}%`)
|
|
|
if (num === 100) {
|
|
|
- oProgressNum.innerHTML = '下载完成';
|
|
|
- } else {
|
|
|
- oProgressNum.innerHTML = '下载进度:' + num + '%';
|
|
|
-
|
|
|
+ loading.dismiss()
|
|
|
}
|
|
|
});
|
|
|
|