controller.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import 'package:dio/dio.dart';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:get/get.dart';
  4. import 'package:vitalapp/managers/interfaces/models/upgrade.dart';
  5. import 'package:vitalapp/managers/interfaces/permission.dart';
  6. import 'package:vitalapp/managers/interfaces/upgrade.dart';
  7. import 'package:vitalapp/pages/upgrade/state.dart';
  8. class AppUpgradeController extends GetxController {
  9. final state = AppUpgradeState();
  10. final upgradeManager = Get.find<IUpgradeManager>();
  11. @override
  12. void onInit() async {
  13. state.currentVersion = await getCurrentVersion();
  14. super.onInit();
  15. }
  16. Future<UpgradeCheckResultModel?> checkNewVersionArrival() async {
  17. final result = await upgradeManager.checkNewVersionArrival();
  18. return result;
  19. }
  20. Future<bool> downloadPackage(String version, String url,
  21. {ValueChanged<double>? onProgress}) async {
  22. final result = await upgradeManager.downloadPackage(version, url,
  23. onProgress: onProgress, cancelToken: state.cancelToken);
  24. return result;
  25. }
  26. Future<void> installPackage(String version) async {
  27. var permissionManager = Get.find<IPermissionManager>();
  28. await permissionManager.requestInstallPackagesPermission();
  29. await upgradeManager.install(version);
  30. }
  31. ///获取当前版本号
  32. Future<String> getCurrentVersion() async {
  33. var version = await upgradeManager.getCurrentVersion();
  34. return version;
  35. }
  36. void deleteFile(String version) async {
  37. await upgradeManager.deleteFile(version);
  38. }
  39. }