12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import 'package:dio/dio.dart';
- import 'package:flutter/foundation.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/managers/interfaces/models/upgrade.dart';
- import 'package:vitalapp/managers/interfaces/permission.dart';
- import 'package:vitalapp/managers/interfaces/upgrade.dart';
- import 'package:vitalapp/pages/upgrade/state.dart';
- class AppUpgradeController extends GetxController {
- final state = AppUpgradeState();
- final upgradeManager = Get.find<IUpgradeManager>();
- @override
- void onInit() async {
- state.currentVersion = await getCurrentVersion();
- super.onInit();
- }
- Future<UpgradeCheckResultModel?> checkNewVersionArrival() async {
- final result = await upgradeManager.checkNewVersionArrival();
- return result;
- }
- Future<bool> downloadPackage(String version, String url,
- {ValueChanged<double>? onProgress}) async {
- final result = await upgradeManager.downloadPackage(version, url,
- onProgress: onProgress, cancelToken: state.cancelToken);
- return result;
- }
- Future<void> installPackage(String version) async {
- var permissionManager = Get.find<IPermissionManager>();
- await permissionManager.requestInstallPackagesPermission();
- await upgradeManager.install(version);
- }
- ///获取当前版本号
- Future<String> getCurrentVersion() async {
- var version = await upgradeManager.getCurrentVersion();
- return version;
- }
- void deleteFile(String version) async {
- await upgradeManager.deleteFile(version);
- }
- }
|