mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-23 08:53:43 +08:00
https://github.com/StarCitizenToolBox/app/issues/1 开发版更新使用 cloudflare 分流
This commit is contained in:
parent
8159e9b70e
commit
52d178a609
@ -18,7 +18,7 @@ import '../../base/ui.dart';
|
|||||||
|
|
||||||
class AppConf {
|
class AppConf {
|
||||||
static const String appVersion = "2.11.0 Beta";
|
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 String appVersionDate = "2024-01-07";
|
||||||
|
|
||||||
static const gameChannels = ["LIVE", "PTU", "EPTU"];
|
static const gameChannels = ["LIVE", "PTU", "EPTU"];
|
||||||
|
@ -24,4 +24,5 @@ class URLConf {
|
|||||||
"$_rssHomeUrl/baidu/tieba/user/%E7%81%AC%E7%81%ACG%E7%81%AC%E7%81%AC&";
|
"$_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 feedbackUrl = "https://txc.qq.com/products/614843";
|
||||||
|
static const devReleaseUrl = "https://git.sctoolbox.sccsgo.com/SCToolBox/Release/releases";
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,23 @@ class UpgradeDialogUI extends BaseUI<UpgradeDialogUIModel> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
|
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) ...[
|
if (model.isUpgrading) ...[
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
Row(
|
Row(
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:markdown/markdown.dart';
|
||||||
import 'package:starcitizen_doctor/api/api.dart';
|
import 'package:starcitizen_doctor/api/api.dart';
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.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:url_launcher/url_launcher_string.dart';
|
||||||
|
import 'package:html/parser.dart';
|
||||||
|
|
||||||
class UpgradeDialogUIModel extends BaseUIModel {
|
class UpgradeDialogUIModel extends BaseUIModel {
|
||||||
String? description;
|
String? description;
|
||||||
String targetVersion = "";
|
String targetVersion = "";
|
||||||
String downloadUrl = "";
|
String downloadUrl = "";
|
||||||
|
String? diversionDownloadUrl;
|
||||||
|
bool isUsingDiversion = false;
|
||||||
|
|
||||||
bool isUpgrading = false;
|
bool isUpgrading = false;
|
||||||
|
|
||||||
double? progress;
|
double? progress;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -25,6 +28,7 @@ class UpgradeDialogUIModel extends BaseUIModel {
|
|||||||
: AppConf.networkVersionData!.lastVersion!;
|
: AppConf.networkVersionData!.lastVersion!;
|
||||||
final r = await Api.getAppReleaseDataByVersionName(targetVersion);
|
final r = await Api.getAppReleaseDataByVersionName(targetVersion);
|
||||||
description = r["body"];
|
description = r["body"];
|
||||||
|
_checkDiversionUrl();
|
||||||
final assets = List.of(r["assets"] ?? []);
|
final assets = List.of(r["assets"] ?? []);
|
||||||
for (var asset in assets) {
|
for (var asset in assets) {
|
||||||
if (asset["name"].toString().endsWith("SETUP.exe")) {
|
if (asset["name"].toString().endsWith("SETUP.exe")) {
|
||||||
@ -41,13 +45,39 @@ class UpgradeDialogUIModel extends BaseUIModel {
|
|||||||
if (AppConf.isMSE) {
|
if (AppConf.isMSE) {
|
||||||
launchUrlString("ms-windows-store://pdp/?productid=9NF3SWFWNKL1");
|
launchUrlString("ms-windows-store://pdp/?productid=9NF3SWFWNKL1");
|
||||||
await Future.delayed(const Duration(seconds: 3));
|
await Future.delayed(const Duration(seconds: 3));
|
||||||
|
if (AppConf.appVersionCode <
|
||||||
|
(AppConf.networkVersionData?.minVersionCode ?? 0)) {
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
Navigator.pop(context!);
|
||||||
|
}
|
||||||
isUpgrading = true;
|
isUpgrading = true;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
final fileName = "${AppConf.getUpgradePath()}/next_SETUP.exe";
|
final fileName = "${AppConf.getUpgradePath()}/next_SETUP.exe";
|
||||||
try {
|
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) {
|
onReceiveProgress: (int count, int total) {
|
||||||
progress = (count / total) * 100;
|
progress = (count / total) * 100;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@ -60,24 +90,45 @@ class UpgradeDialogUIModel extends BaseUIModel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
final r = await (Process.run(
|
// final r = await (Process.run(
|
||||||
SystemHelper.powershellPath, ["start", fileName, "/SILENT"]));
|
// SystemHelper.powershellPath, ["start", fileName, "/SILENT"]));
|
||||||
if (r.stderr.toString().isNotEmpty) {
|
// if (r.stderr.toString().isNotEmpty) {
|
||||||
throw r.stderr;
|
// throw r.stderr;
|
||||||
}
|
// }
|
||||||
exit(0);
|
// exit(0);
|
||||||
} catch (_) {
|
// } catch (_) {
|
||||||
isUpgrading = false;
|
// isUpgrading = false;
|
||||||
progress = null;
|
// progress = null;
|
||||||
showToast(context!, "运行失败,请尝试手动安装!");
|
// showToast(context!, "运行失败,请尝试手动安装!");
|
||||||
Process.run(SystemHelper.powershellPath,
|
// Process.run(SystemHelper.powershellPath,
|
||||||
["explorer.exe", "/select,\"$fileName\""]);
|
// ["explorer.exe", "/select,\"$fileName\""]);
|
||||||
notifyListeners();
|
// notifyListeners();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void doCancel() {
|
void doCancel() {
|
||||||
Navigator.pop(context!, true);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ dependencies:
|
|||||||
hive: ^2.2.3
|
hive: ^2.2.3
|
||||||
path_provider: ^2.1.1
|
path_provider: ^2.1.1
|
||||||
dio: ^5.3.3
|
dio: ^5.3.3
|
||||||
|
markdown: ^7.2.1
|
||||||
markdown_widget: ^2.2.0
|
markdown_widget: ^2.2.0
|
||||||
extended_image: ^8.2.0
|
extended_image: ^8.2.0
|
||||||
device_info_plus: ^9.0.3
|
device_info_plus: ^9.0.3
|
||||||
|
Loading…
Reference in New Issue
Block a user