diff --git a/lib/common/conf/app_conf.dart b/lib/common/conf/app_conf.dart index 606f1bf..4e3a1a8 100644 --- a/lib/common/conf/app_conf.dart +++ b/lib/common/conf/app_conf.dart @@ -18,7 +18,7 @@ import '../../base/ui.dart'; class AppConf { static const String appVersion = "2.11.0 Beta"; - static const int appVersionCode = 36; + static const int appVersionCode = 35; static const String appVersionDate = "2024-01-07"; static const gameChannels = ["LIVE", "PTU", "EPTU"]; diff --git a/lib/common/conf/url_conf.dart b/lib/common/conf/url_conf.dart index 9326b4f..60c7ced 100644 --- a/lib/common/conf/url_conf.dart +++ b/lib/common/conf/url_conf.dart @@ -24,4 +24,5 @@ class URLConf { "$_rssHomeUrl/baidu/tieba/user/%E7%81%AC%E7%81%ACG%E7%81%AC%E7%81%AC&"; static const feedbackUrl = "https://txc.qq.com/products/614843"; + static const devReleaseUrl = "https://git.sctoolbox.sccsgo.com/SCToolBox/Release/releases"; } diff --git a/lib/ui/settings/upgrade_dialog_ui.dart b/lib/ui/settings/upgrade_dialog_ui.dart index 8cd8c9f..67240ec 100644 --- a/lib/ui/settings/upgrade_dialog_ui.dart +++ b/lib/ui/settings/upgrade_dialog_ui.dart @@ -41,6 +41,23 @@ class UpgradeDialogUI extends BaseUI { ), ), )), + if (model.isUsingDiversion) ...[ + const SizedBox(height: 24), + GestureDetector( + onTap: model.launchReleaseUrl, + child: Container( + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + color: Colors.white.withOpacity(.1), + borderRadius: BorderRadius.circular(7)), + child: Text( + "提示:当前正在使用分流服务器进行更新,可能会出现下载速度下降,但有助于我们进行成本控制,若下载异常请点击这里跳转手动安装。", + style: TextStyle( + fontSize: 14, color: Colors.white.withOpacity(.7)), + ), + ), + ), + ], if (model.isUpgrading) ...[ const SizedBox(height: 24), Row( diff --git a/lib/ui/settings/upgrade_dialog_ui_model.dart b/lib/ui/settings/upgrade_dialog_ui_model.dart index dc95f95..0634feb 100644 --- a/lib/ui/settings/upgrade_dialog_ui_model.dart +++ b/lib/ui/settings/upgrade_dialog_ui_model.dart @@ -1,19 +1,22 @@ import 'dart:io'; import 'package:dio/dio.dart'; +import 'package:markdown/markdown.dart'; import 'package:starcitizen_doctor/api/api.dart'; import 'package:starcitizen_doctor/base/ui_model.dart'; import 'package:starcitizen_doctor/common/conf/app_conf.dart'; -import 'package:starcitizen_doctor/common/helper/system_helper.dart'; +import 'package:starcitizen_doctor/common/conf/url_conf.dart'; import 'package:url_launcher/url_launcher_string.dart'; +import 'package:html/parser.dart'; class UpgradeDialogUIModel extends BaseUIModel { String? description; String targetVersion = ""; String downloadUrl = ""; + String? diversionDownloadUrl; + bool isUsingDiversion = false; bool isUpgrading = false; - double? progress; @override @@ -25,6 +28,7 @@ class UpgradeDialogUIModel extends BaseUIModel { : AppConf.networkVersionData!.lastVersion!; final r = await Api.getAppReleaseDataByVersionName(targetVersion); description = r["body"]; + _checkDiversionUrl(); final assets = List.of(r["assets"] ?? []); for (var asset in assets) { if (asset["name"].toString().endsWith("SETUP.exe")) { @@ -41,13 +45,39 @@ class UpgradeDialogUIModel extends BaseUIModel { if (AppConf.isMSE) { launchUrlString("ms-windows-store://pdp/?productid=9NF3SWFWNKL1"); await Future.delayed(const Duration(seconds: 3)); - exit(0); + if (AppConf.appVersionCode < + (AppConf.networkVersionData?.minVersionCode ?? 0)) { + exit(0); + } + Navigator.pop(context!); } isUpgrading = true; notifyListeners(); final fileName = "${AppConf.getUpgradePath()}/next_SETUP.exe"; try { - await Dio().download(downloadUrl, fileName, + // check diversionDownloadUrl + var url = downloadUrl; + final dio = Dio(); + if (diversionDownloadUrl != null) { + try { + final resp = await dio.head(diversionDownloadUrl!, + options: Options( + sendTimeout: const Duration(seconds: 10), + receiveTimeout: const Duration(seconds: 10))); + if (resp.statusCode == 200) { + isUsingDiversion = true; + url = diversionDownloadUrl!; + notifyListeners(); + } else { + isUsingDiversion = false; + notifyListeners(); + } + dPrint("diversionDownloadUrl head resp == ${resp.headers}"); + } catch (e) { + dPrint("diversionDownloadUrl err:$e"); + } + } + await dio.download(url, fileName, onReceiveProgress: (int count, int total) { progress = (count / total) * 100; notifyListeners(); @@ -60,24 +90,45 @@ class UpgradeDialogUIModel extends BaseUIModel { return; } - try { - final r = await (Process.run( - SystemHelper.powershellPath, ["start", fileName, "/SILENT"])); - if (r.stderr.toString().isNotEmpty) { - throw r.stderr; - } - exit(0); - } catch (_) { - isUpgrading = false; - progress = null; - showToast(context!, "运行失败,请尝试手动安装!"); - Process.run(SystemHelper.powershellPath, - ["explorer.exe", "/select,\"$fileName\""]); - notifyListeners(); - } + // try { + // final r = await (Process.run( + // SystemHelper.powershellPath, ["start", fileName, "/SILENT"])); + // if (r.stderr.toString().isNotEmpty) { + // throw r.stderr; + // } + // exit(0); + // } catch (_) { + // isUpgrading = false; + // progress = null; + // showToast(context!, "运行失败,请尝试手动安装!"); + // Process.run(SystemHelper.powershellPath, + // ["explorer.exe", "/select,\"$fileName\""]); + // notifyListeners(); + // } } void doCancel() { Navigator.pop(context!, true); } + + void _checkDiversionUrl() { + try { + final htmlStr = markdownToHtml(description!); + final html = parse(htmlStr); + html.querySelectorAll('a').forEach((element) { + String linkText = element.text; + String linkUrl = element.attributes['href'] ?? ''; + if (linkText.trim().endsWith("_SETUP.exe")) { + diversionDownloadUrl = linkUrl.trim(); + dPrint("diversionDownloadUrl === $diversionDownloadUrl"); + } + }); + } catch (e) { + dPrint("_checkDiversionUrl Error:$e"); + } + } + + void launchReleaseUrl() { + launchUrlString(URLConf.devReleaseUrl); + } } diff --git a/pubspec.yaml b/pubspec.yaml index 60a94de..a1209f5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,6 +41,7 @@ dependencies: hive: ^2.2.3 path_provider: ^2.1.1 dio: ^5.3.3 + markdown: ^7.2.1 markdown_widget: ^2.2.0 extended_image: ^8.2.0 device_info_plus: ^9.0.3