|
|
|
@ -177,9 +177,9 @@ class OtaUpgradeController extends GetxController { |
|
|
|
// 版本更新 |
|
|
|
Future<void> checkUpdate() async { |
|
|
|
try { |
|
|
|
if (latestVersion.value != "") |
|
|
|
if (latestVersion.value != "") { |
|
|
|
_showUpdateDialog(latestVersion.value); |
|
|
|
else { |
|
|
|
} else { |
|
|
|
Get.snackbar('错误', '获取最新版本信息失败'); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
@ -187,26 +187,28 @@ class OtaUpgradeController extends GetxController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 显示更新对话框 |
|
|
|
void _showUpdateDialog(String latest) { |
|
|
|
void _showUpdateDialog(String latest) async { |
|
|
|
print('显示更新对话框'); |
|
|
|
Get.dialog( |
|
|
|
AlertDialog( |
|
|
|
title: Text('发现新版本 $latest'), |
|
|
|
content: Text('是否立即更新?'), |
|
|
|
actions: [ |
|
|
|
TextButton( |
|
|
|
onPressed: () { |
|
|
|
if (Get.isDialogOpen!) { |
|
|
|
Get.back(); // 确保只关闭对话框 |
|
|
|
} |
|
|
|
onPressed: () async { |
|
|
|
print('取消按钮被点击'); |
|
|
|
|
|
|
|
Get.back(); |
|
|
|
Future.delayed(Duration(milliseconds: 300)); |
|
|
|
}, |
|
|
|
child: Text('取消'), |
|
|
|
), |
|
|
|
TextButton( |
|
|
|
onPressed: () { |
|
|
|
if (Get.isDialogOpen!) { |
|
|
|
Get.back(); // 确保只关闭对话框 |
|
|
|
} |
|
|
|
onPressed: () async { |
|
|
|
print('更新按钮被点击'); |
|
|
|
|
|
|
|
Get.back(); |
|
|
|
Future.delayed(Duration(milliseconds: 300)); |
|
|
|
startDownload(); |
|
|
|
}, |
|
|
|
child: Text('更新'), |
|
|
|
@ -266,7 +268,7 @@ class OtaUpgradeController extends GetxController { |
|
|
|
if (existingSameFile) { |
|
|
|
Get.snackbar('文件已存在', '跳过下载,直接更新'); |
|
|
|
|
|
|
|
_installApp(savePath); |
|
|
|
startUpgrading(savePath); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
@ -309,7 +311,7 @@ class OtaUpgradeController extends GetxController { |
|
|
|
Get.snackbar('错误', '文件未找到,请检查写入权限'); |
|
|
|
} |
|
|
|
isDownloading.value = false; |
|
|
|
_installApp(savePath); |
|
|
|
startUpgrading(savePath); |
|
|
|
return; |
|
|
|
} on DioException catch (e) { |
|
|
|
Get.snackbar('下载失败', '错误: ${e.message}'); |
|
|
|
@ -321,8 +323,8 @@ class OtaUpgradeController extends GetxController { |
|
|
|
} |
|
|
|
|
|
|
|
// 开始升级 |
|
|
|
void _installApp(String path) async { |
|
|
|
jlota.searchDevices(path); |
|
|
|
void startUpgrading(String path) async { |
|
|
|
jlota.startUpgrading(path); |
|
|
|
return; |
|
|
|
// isUpgrade.value = false; |
|
|
|
} |
|
|
|
|