支持备线切换

This commit is contained in:
xkeyC 2024-02-03 12:28:15 +08:00
parent 26bfa108a1
commit 72bcaf02cd
9 changed files with 184 additions and 41 deletions

View File

@ -11,7 +11,7 @@ class AnalyticsApi {
if (kDebugMode) return; if (kDebugMode) return;
dPrint("AnalyticsApi.touch === $key start"); dPrint("AnalyticsApi.touch === $key start");
try { try {
await _dio.post("${URLConf.xkeycApiUrl}/analytics/$key"); await _dio.post("${URLConf.xkeycApiHome}/analytics/$key");
dPrint("AnalyticsApi.touch === $key over"); dPrint("AnalyticsApi.touch === $key over");
} catch (e) { } catch (e) {
dPrint("AnalyticsApi.touch === $key Error:$e"); dPrint("AnalyticsApi.touch === $key Error:$e");

View File

@ -23,7 +23,7 @@ class BaseUIContainer extends ConsumerStatefulWidget {
ConsumerState<BaseUIContainer> createState() => uiCreate(); ConsumerState<BaseUIContainer> createState() => uiCreate();
Future push(BuildContext context) { Future push(BuildContext context) {
return Navigator.push(context, makeRoute(context, this)); return Navigator.push(context, makeRoute(context));
} }
// Future pushShowModalBottomSheet(BuildContext context) { // Future pushShowModalBottomSheet(BuildContext context) {
@ -37,11 +37,10 @@ class BaseUIContainer extends ConsumerStatefulWidget {
// } // }
/// ///
FluentPageRoute makeRoute( FluentPageRoute makeRoute(BuildContext context) {
BuildContext context, BaseUIContainer baseUIContainer) {
return MyPageRoute( return MyPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
return baseUIContainer; return this;
}, },
); );
} }

View File

@ -99,8 +99,6 @@ class AppConf {
); );
} }
}); });
await checkUpdate();
AnalyticsApi.touch("launch");
} }
static String getUpgradePath() { static String getUpgradePath() {

View File

@ -1,28 +1,89 @@
import 'package:dio/dio.dart';
import 'package:starcitizen_doctor/base/ui_model.dart';
class URLConf { class URLConf {
static const String giteaAttachmentsUrl = /// HOME API
"https://git.sctoolbox.sccsgo.com/SCToolBox/Release"; static String gitApiHome = "https://git.sctoolbox.sccsgo.com";
static const String gitlabLocalizationUrl = static String rssApiHome = "https://rss.sctoolbox.sccsgo.com";
"https://git.sctoolbox.sccsgo.com/SCToolBox/LocalizationData"; static const String xkeycApiHome = "https://sctoolbox.xkeyc.com";
static const String apiRepoPath =
"https://git.sctoolbox.sccsgo.com/SCToolBox/api/raw/branch/main/";
static const String gitlabApiPath = static bool isUsingFallback = false;
"https://git.sctoolbox.sccsgo.com/api/v1/";
static const String webTranslateHomeUrl = /// URLS
"https://git.sctoolbox.sccsgo.com/SCToolBox/ScWeb_Chinese_Translate/raw/branch/main/json/locales"; static String giteaAttachmentsUrl = "$gitApiHome/SCToolBox/Release";
static String gitlabLocalizationUrl =
"$gitApiHome/SCToolBox/LocalizationData";
static String apiRepoPath = "$gitApiHome/SCToolBox/api/raw/branch/main/";
static const String xkeycApiUrl = "https://sctoolbox.xkeyc.com"; static String gitlabApiPath = "https://$gitApiHome/api/v1/";
static const _rssHomeUrl = "https://rss.sctoolbox.sccsgo.com"; static String webTranslateHomeUrl =
"$gitApiHome/SCToolBox/ScWeb_Chinese_Translate/raw/branch/main/json/locales";
static const rssVideoUrl = static String rssVideoUrl =
"$_rssHomeUrl/bilibili/user/channel/27976358/290653"; "$rssApiHome/bilibili/user/channel/27976358/290653";
static const rssTextUrl1 = "$_rssHomeUrl/bilibili/user/article/40102960"; static String rssTextUrl1 = "$rssApiHome/bilibili/user/article/40102960";
static const rssTextUrl2 = static String rssTextUrl2 =
"$_rssHomeUrl/baidu/tieba/user/%E7%81%AC%E7%81%ACG%E7%81%AC%E7%81%AC&"; "$rssApiHome/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";
static const devReleaseUrl =
"https://git.sctoolbox.sccsgo.com/SCToolBox/Release/releases";
static const _gitApiList = [
"https://git.sctoolbox.sccsgo.com",
"https://sctb-git.xkeyc.com"
];
static const _rssApiList = [
"https://rss.sctoolbox.sccsgo.com",
"https://rss.42kit.com"
];
static checkHost() async {
final dio = Dio(BaseOptions(connectTimeout: const Duration(seconds: 5)));
bool hasAvailable = false;
// git API
for (var value in _gitApiList) {
try {
final resp = await dio.head(value);
if (resp.statusCode == 200) {
dPrint("[URLConf].checkHost passed $value");
gitApiHome = value;
hasAvailable = true;
break;
}
isUsingFallback = true;
continue;
} catch (e) {
dPrint("[URLConf].checkHost $value Error= $e");
isUsingFallback = true;
continue;
}
}
// RSS API
for (var value in _rssApiList) {
try {
final resp = await dio.head(value);
if (resp.statusCode == 200) {
rssApiHome = value;
hasAvailable = true;
dPrint("[URLConf].checkHost passed $value");
break;
}
isUsingFallback = true;
continue;
} catch (e) {
dPrint("[URLConf].checkHost $value Error= $e");
isUsingFallback = true;
continue;
}
}
if (!hasAvailable) {
isUsingFallback = false;
}
}
} }

View File

@ -2,11 +2,11 @@ import 'package:desktop_webview_window/desktop_webview_window.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.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/ui/index_ui_model.dart'; import 'package:starcitizen_doctor/ui/splash_ui_model.dart';
import 'package:window_manager/window_manager.dart'; import 'package:window_manager/window_manager.dart';
import 'global_ui_model.dart'; import 'global_ui_model.dart';
import 'ui/index_ui.dart'; import 'ui/splash_ui.dart';
void main(List<String> args) async { void main(List<String> args) async {
if (runWebViewTitleBarWidget(args, if (runWebViewTitleBarWidget(args,
@ -53,7 +53,7 @@ class AppUI extends BaseUI {
))), ))),
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
home: BaseUIContainer( home: BaseUIContainer(
uiCreate: () => IndexUI(), modelCreate: () => IndexUIModel()), uiCreate: () => SplashUI(), modelCreate: () => SplashUIModel()),
); );
} }

View File

@ -113,11 +113,7 @@ class HomeUIModel extends BaseUIModel {
.data)); .data));
countdownFestivalListData = await Api.getFestivalCountdownList(); countdownFestivalListData = await Api.getFestivalCountdownList();
notifyListeners(); notifyListeners();
try {
_loadRRS(); _loadRRS();
} catch (e) {
dPrint("_loadRRS Error:$e");
}
} catch (e) { } catch (e) {
dPrint(e); dPrint(e);
} }
@ -139,6 +135,12 @@ class HomeUIModel extends BaseUIModel {
appUpdateTimer = Timer.periodic(const Duration(minutes: 30), (timer) { appUpdateTimer = Timer.periodic(const Duration(minutes: 30), (timer) {
_checkLocalizationUpdate(); _checkLocalizationUpdate();
}); });
Future.delayed(const Duration(milliseconds: 100)).then((value) {
if (URLConf.isUsingFallback) {
if (!mounted) return;
showToast(context!, "因源服务器异常(机房故障或遭受攻击),当前正在使用备用线路,可能会出现访问速度下降,敬请谅解。");
}
});
super.initModel(); super.initModel();
} }
@ -187,6 +189,7 @@ class HomeUIModel extends BaseUIModel {
} }
Future _loadRRS() async { Future _loadRRS() async {
try {
final v = await RSSApi.getRssVideo(); final v = await RSSApi.getRssVideo();
rssVideoItems = v; rssVideoItems = v;
notifyListeners(); notifyListeners();
@ -194,6 +197,9 @@ class HomeUIModel extends BaseUIModel {
rssTextItems = t; rssTextItems = t;
notifyListeners(); notifyListeners();
dPrint("RSS update Success !"); dPrint("RSS update Success !");
} catch (e) {
dPrint("_loadRRS Error:$e");
}
} }
VoidCallback? doCheck() { VoidCallback? doCheck() {

View File

@ -207,7 +207,7 @@ class WebViewModel {
/// https://github.com/CxJuice/Uex_Chinese_Translate /// https://github.com/CxJuice/Uex_Chinese_Translate
// get versions // get versions
const hostUrl = URLConf.webTranslateHomeUrl; final hostUrl = URLConf.webTranslateHomeUrl;
dPrint("AppWebLocalizationVersionsData === ${v.toJson()}"); dPrint("AppWebLocalizationVersionsData === ${v.toJson()}");
localizationResource["zh-CN"] = await _getJson("$hostUrl/zh-CN-rsi.json", localizationResource["zh-CN"] = await _getJson("$hostUrl/zh-CN-rsi.json",

45
lib/ui/splash_ui.dart Normal file
View File

@ -0,0 +1,45 @@
import 'package:starcitizen_doctor/base/ui.dart';
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
import 'splash_ui_model.dart';
class SplashUI extends BaseUI<SplashUIModel> {
@override
Widget? buildBody(BuildContext context, SplashUIModel model) {
return makeDefaultPage(context, model,
content: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset("assets/app_logo.png", width: 192, height: 192),
const SizedBox(height: 32),
const ProgressRing(),
const SizedBox(height: 32),
if (model.step == 0) const Text("正在检测可用性,这可能需要一点时间..."),
if (model.step == 1) const Text("正在检查更新..."),
if (model.step == 2) const Text("即将完成..."),
],
),
),
automaticallyImplyLeading: false,
titleRow: Align(
alignment: AlignmentDirectional.centerStart,
child: Row(
children: [
Image.asset(
"assets/app_logo_mini.png",
width: 20,
height: 20,
fit: BoxFit.cover,
),
const SizedBox(width: 12),
const Text(
"SC汉化盒子 V${AppConf.appVersion} ${AppConf.isMSE ? "" : " Dev"}")
],
),
));
}
@override
String getUITitle(BuildContext context, SplashUIModel model) => "";
}

View File

@ -0,0 +1,34 @@
import 'package:starcitizen_doctor/api/analytics.dart';
import 'package:starcitizen_doctor/base/ui_model.dart';
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
import 'package:starcitizen_doctor/ui/index_ui.dart';
import 'package:starcitizen_doctor/ui/index_ui_model.dart';
import '../common/conf/app_conf.dart';
class SplashUIModel extends BaseUIModel {
int step = 0;
@override
void initModel() {
_initApp();
super.initModel();
}
Future<void> _initApp() async {
AnalyticsApi.touch("launch");
await URLConf.checkHost();
step = 1;
notifyListeners();
await AppConf.checkUpdate();
step = 2;
notifyListeners();
Future.delayed(const Duration(milliseconds: 300));
Navigator.pushAndRemoveUntil(
context!,
BaseUIContainer(
uiCreate: () => IndexUI(),
modelCreate: () => IndexUIModel()).makeRoute(context!),
(route) => false);
}
}