From 31626efa9ffb0fd134ac28f5d1f80c1382eb7e37 Mon Sep 17 00:00:00 2001 From: xkeyC <3334969096@qq.com> Date: Fri, 5 Sep 2025 16:02:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=5FfixFestivalCountdownListDateTime=20?= =?UTF-8?q?=E8=8A=82=E6=97=A5=E5=B7=B2=E8=BF=877=E5=A4=A9=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E6=96=B0=E4=B8=BA=E4=B8=8B=E4=B8=80=E5=B9=B4?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/home/home_ui_model.dart | 64 +++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/lib/ui/home/home_ui_model.dart b/lib/ui/home/home_ui_model.dart index 904def9..b3d7075 100644 --- a/lib/ui/home/home_ui_model.dart +++ b/lib/ui/home/home_ui_model.dart @@ -136,14 +136,13 @@ class HomeUIModel extends _$HomeUIModel { } // ignore: avoid_build_context_in_providers - Future goWebView( - BuildContext context, - String title, - String url, { - bool useLocalization = false, - bool loginMode = false, - RsiLoginCallback? rsiLoginCallback, - }) async { + Future goWebView(BuildContext context, + String title, + String url, { + bool useLocalization = false, + bool loginMode = false, + RsiLoginCallback? rsiLoginCallback, + }) async { if (useLocalization) { const tipVersion = 2; final box = await Hive.openBox("app_conf"); @@ -154,7 +153,10 @@ class HomeUIModel extends _$HomeUIModel { context, S.current.home_action_title_star_citizen_website_localization, Text(S.current.home_action_info_web_localization_plugin_disclaimer, style: const TextStyle(fontSize: 16)), - constraints: BoxConstraints(maxWidth: MediaQuery.of(context).size.width * .6), + constraints: BoxConstraints(maxWidth: MediaQuery + .of(context) + .size + .width * .6), ); if (!ok) { if (loginMode) { @@ -225,8 +227,7 @@ class HomeUIModel extends _$HomeUIModel { final box = await Hive.openBox("app_conf"); final version = box.get("close_placard", defaultValue: ""); if (r.enable == true) { - if (r.alwaysShow != true && version == r.version) { - } else { + if (r.alwaysShow != true && version == r.version) {} else { state = state.copyWith(appPlacardData: r); } } @@ -237,7 +238,7 @@ class HomeUIModel extends _$HomeUIModel { final countdownFestivalListData = await Api.getFestivalCountdownList(); state = state.copyWith( webLocalizationVersionsData: appWebLocalizationVersionsData, - countdownFestivalListData: countdownFestivalListData, + countdownFestivalListData: _fixFestivalCountdownListDateTime(countdownFestivalListData), ); _updateSCServerStatus(); _loadRRS(); @@ -248,6 +249,31 @@ class HomeUIModel extends _$HomeUIModel { checkLocalizationUpdate(); } + /// 节日已过7天时,更新为下一年的时间 + List _fixFestivalCountdownListDateTime(List list) { + final now = DateTime.now(); + + return list.map((item) { + if (item.time == null) return item; + final itemDateTime = DateTime.fromMillisecondsSinceEpoch(item.time! * 1000); + final itemDatePlusSeven = itemDateTime.add(const Duration(days: 7)); + if (itemDatePlusSeven.isBefore(now)) { + final nextYearDate = DateTime( + now.year + 1, + itemDateTime.month, + itemDateTime.day, + itemDateTime.hour, + itemDateTime.minute, + itemDateTime.second, + ); + final newTimestamp = (nextYearDate.millisecondsSinceEpoch / 1000).round(); + return CountdownFestivalItemData(name: item.name, time: newTimestamp, icon: item.icon); + } + + return item; + }).toList(); + } + Future _updateSCServerStatus() async { try { final s = await Api.getScServerStatus(); @@ -336,14 +362,12 @@ class HomeUIModel extends _$HomeUIModel { ref.read(localizationUIModelProvider.notifier).onChangeGameInstallPath(value); } - Future doLaunchGame( - // ignore: avoid_build_context_in_providers - BuildContext context, - String launchExe, - List args, - String installPath, - String? processorAffinity, - ) async { + Future doLaunchGame(// ignore: avoid_build_context_in_providers + BuildContext context, + String launchExe, + List args, + String installPath, + String? processorAffinity,) async { var runningMap = Map.from(state.isGameRunning); runningMap[installPath] = true; state = state.copyWith(isGameRunning: runningMap);