This commit is contained in:
xkeyC 2023-10-28 19:58:26 +08:00
parent d63d07a1a9
commit 5606dd0b87
5 changed files with 163 additions and 106 deletions

View File

@ -23,6 +23,8 @@ class AppConf {
"https://jihulab.com/StarCitizenCN_Community/api/-/raw/main/";
static const String gitlabApiPath = "https://jihulab.com/api/v4/";
static const String webTranslateHomeUrl= "https://ch.citizenwiki.cn/json-files/locales";
static late final String applicationSupportDir;
static AppVersionData? networkVersionData;

View File

@ -83,7 +83,9 @@ class HomeUI extends BaseUI<HomeUIModel> {
Positioned(
top: 0,
right: 24,
child: Container(
child: Stack(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: FluentTheme.of(context).cardColor.withOpacity(.03),
@ -145,8 +147,8 @@ class HomeUI extends BaseUI<HomeUIModel> {
Row(
children: [
Button(
child:
const FaIcon(FontAwesomeIcons.chrome, size: 18),
child: const FaIcon(FontAwesomeIcons.chrome,
size: 18),
onPressed: () {
launchUrlString(
"https://chrome.google.com/webstore/detail/gocnjckojmledijgmadmacoikibcggja?authuser=0&hl=zh-CN");
@ -154,7 +156,8 @@ class HomeUI extends BaseUI<HomeUIModel> {
),
const SizedBox(width: 12),
Button(
child: const FaIcon(FontAwesomeIcons.edge, size: 18),
child:
const FaIcon(FontAwesomeIcons.edge, size: 18),
onPressed: () {
launchUrlString(
"https://microsoftedge.microsoft.com/addons/detail/lipbbcckldklpdcpfagicipecaacikgi");
@ -162,7 +165,8 @@ class HomeUI extends BaseUI<HomeUIModel> {
),
const SizedBox(width: 12),
Button(
child: const FaIcon(FontAwesomeIcons.firefoxBrowser,
child: const FaIcon(
FontAwesomeIcons.firefoxBrowser,
size: 18),
onPressed: () {
launchUrlString(
@ -172,8 +176,8 @@ class HomeUI extends BaseUI<HomeUIModel> {
),
const SizedBox(width: 12),
Button(
child:
const FaIcon(FontAwesomeIcons.github, size: 18),
child: const FaIcon(FontAwesomeIcons.github,
size: 18),
onPressed: () {
launchUrlString(
"https://github.com/xkeyC/StarCitizenBoxBrowserEx");
@ -185,6 +189,18 @@ class HomeUI extends BaseUI<HomeUIModel> {
),
),
),
if (model.appWebLocalizationVersionsData == null)
Positioned.fill(
child: Container(
decoration: BoxDecoration(
color: Colors.black.withOpacity(.3),
borderRadius: BorderRadius.circular(12)),
child: const Center(
child: ProgressRing(),
),
))
],
),
),
Positioned(
left: 24,
@ -297,13 +313,20 @@ class HomeUI extends BaseUI<HomeUIModel> {
AnimatedSize(
duration: const Duration(milliseconds: 130),
child: Button(
onPressed: model.appWebLocalizationVersionsData == null
? null
: () => model.launchRSI(),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(model.isCurGameRunning
child: Icon(
model.isCurGameRunning
? FluentIcons.stop_solid
: FluentIcons.play),
: FluentIcons.play,
color: model.isCurGameRunning
? Colors.red.withOpacity(.8)
: null,
),
onPressed: () => model.launchRSI()),
)),
),
const SizedBox(width: 12),
Button(

View File

@ -3,6 +3,7 @@ import 'dart:convert';
import 'dart:io';
import 'package:desktop_webview_window/desktop_webview_window.dart';
import 'package:dio/dio.dart';
import 'package:hive/hive.dart';
import 'package:starcitizen_doctor/api/api.dart';
import 'package:starcitizen_doctor/base/ui_model.dart';
@ -10,6 +11,7 @@ import 'package:starcitizen_doctor/common/conf.dart';
import 'package:starcitizen_doctor/common/helper/log_helper.dart';
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
import 'package:starcitizen_doctor/data/app_placard_data.dart';
import 'package:starcitizen_doctor/data/app_web_localization_versions_data.dart';
import 'package:starcitizen_doctor/ui/home/dialogs/md_content_dialog_ui.dart';
import 'package:starcitizen_doctor/ui/home/dialogs/md_content_dialog_ui_model.dart';
import 'package:starcitizen_doctor/ui/home/localization/localization_ui_model.dart';
@ -49,6 +51,8 @@ class HomeUIModel extends BaseUIModel {
List<MapEntry<String, String>>? checkResult;
AppWebLocalizationVersionsData? appWebLocalizationVersionsData;
final cnExp = RegExp(r"[^\x00-\xff]");
AppPlacardData? appPlacardData;
@ -77,6 +81,10 @@ class HomeUIModel extends BaseUIModel {
appPlacardData = r;
}
}
appWebLocalizationVersionsData = AppWebLocalizationVersionsData.fromJson(
(await Api.dio.get("${AppConf.webTranslateHomeUrl}/versions.json",
options: Options(responseType: ResponseType.json)))
.data);
} catch (e) {
dPrint(e);
}
@ -434,7 +442,7 @@ class HomeUIModel extends BaseUIModel {
isFixing = true;
notifyListeners();
try {
await webViewModel.initLocalization();
await webViewModel.initLocalization(appWebLocalizationVersionsData!);
} catch (e) {
showToast(context!, "初始化网页汉化资源失败!$e");
}

View File

@ -53,6 +53,33 @@ class LoginDialogModel extends BaseUIModel {
.replaceAll("\")", "");
Map<String, dynamic> payload = Jwt.parseJwt(authToken!);
nickname = payload["nickname"] ?? "";
final buildInfoFile = File("$installPath\\build_manifest.id");
if (await buildInfoFile.exists()) {
final buildInfo =
json.decode(await buildInfoFile.readAsString())["Data"];
dPrint("buildInfo ======= $buildInfo");
if (releaseInfo?["versionLabel"] != null &&
buildInfo["RequestedP4ChangeNum"] != null) {
if (!(releaseInfo!["versionLabel"]!
.toString()
.endsWith(buildInfo["RequestedP4ChangeNum"]!.toString()))) {
final ok = await showConfirmDialogs(
context!,
"游戏版本过期",
Text(
"RSI 服务器报告版本号:${releaseInfo?["versionLabel"]} \n\n本地版本号:${buildInfo["RequestedP4ChangeNum"]} \n\n建议使用 RSI Launcher 更新游戏!"),
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context!).size.width * .4),
cancel: "忽略");
if (ok == true) {
Navigator.pop(context!);
return;
}
}
}
}
_readyForLaunch();
}, useLocalization: true);
}
@ -98,7 +125,8 @@ class LoginDialogModel extends BaseUIModel {
loginChannel: getChannelID());
if (useLocalization) {
try {
await webViewModel.initLocalization();
await webViewModel
.initLocalization(homeUIModel.appWebLocalizationVersionsData!);
} catch (_) {}
}
await webViewModel.initWebView(

View File

@ -167,16 +167,12 @@ class WebViewModel {
webview.launch(url);
}
initLocalization() async {
initLocalization(AppWebLocalizationVersionsData v) async {
localizationScript = await rootBundle.loadString('assets/web_script.js');
/// https://github.com/CxJuice/Uex_Chinese_Translate
// get versions
const hostUrl = "https://ch.citizenwiki.cn/json-files/locales";
final v = AppWebLocalizationVersionsData.fromJson(
await _getJson("$hostUrl/versions.json"));
const hostUrl = AppConf.webTranslateHomeUrl;
dPrint("AppWebLocalizationVersionsData === ${v.toJson()}");
localizationResource["zh-CN"] = await _getJson("$hostUrl/zh-CN-rsi.json",