From 7c833fe3acfe84fe15e607cfee884ed55d3a703d Mon Sep 17 00:00:00 2001 From: xkeyC <3334969096@qq.com> Date: Sat, 11 Nov 2023 01:18:30 +0800 Subject: [PATCH] ee --- lib/common/conf.dart | 15 +++++++-- lib/data/app_version_data.dart | 12 ++++---- lib/global_ui_model.dart | 53 +++++++++++++++++++++++++++----- lib/main.dart | 12 +++----- lib/ui/about/about_ui_model.dart | 2 +- lib/ui/index_ui_model.dart | 2 +- 6 files changed, 71 insertions(+), 25 deletions(-) diff --git a/lib/common/conf.dart b/lib/common/conf.dart index 025f7e1..575f582 100644 --- a/lib/common/conf.dart +++ b/lib/common/conf.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter_acrylic/flutter_acrylic.dart'; +import 'package:hexcolor/hexcolor.dart'; import 'package:hive/hive.dart'; import 'package:path_provider/path_provider.dart'; import 'package:starcitizen_doctor/api/analytics.dart'; @@ -43,6 +44,10 @@ class AppConf { static late final WindowsDeviceInfo windowsDeviceInfo; + static Color? colorBackground; + static Color? colorMenu; + static Color? colorMica; + static const isMSE = String.fromEnvironment("MSE", defaultValue: "false") == "true"; @@ -80,6 +85,11 @@ class AppConf { await SystemHelper.initPowershellPath(); isRunningAdmin = await globalUIModel.checkAdmin(); + /// init defaultColor + colorBackground = HexColor("#132431").withOpacity(.75); + colorMenu = HexColor("#132431").withOpacity(.95); + colorMica = HexColor("#0A3142"); + /// init windows await windowManager.ensureInitialized(); windowManager.waitUntilReadyToShow().then((_) async { @@ -100,7 +110,7 @@ class AppConf { ); } }); - await _checkUpdate(); + await checkUpdate(); AnalyticsApi.touch("launch"); } @@ -108,7 +118,7 @@ class AppConf { return "${AppConf.applicationSupportDir}/._upgrade"; } - static Future _checkUpdate() async { + static Future checkUpdate() async { // clean path if (!isMSE) { final dir = Directory(getUpgradePath()); @@ -118,6 +128,7 @@ class AppConf { } try { networkVersionData = await Api.getAppVersion(); + globalUIModel.checkActivityThemeColor(); dPrint( "lastVersion=${networkVersionData?.lastVersion} ${networkVersionData?.lastVersionCode}"); } catch (e) { diff --git a/lib/data/app_version_data.dart b/lib/data/app_version_data.dart index a902b72..3dcf76d 100644 --- a/lib/data/app_version_data.dart +++ b/lib/data/app_version_data.dart @@ -5,7 +5,7 @@ /// MSE_lastVersionCode : 27 /// MSE_minVersionCode : 27 /// p4kDownloadUrl : "https://p4k.42kit.com/Data.p4k" -/// activityColors : {"enable":true,"startTime":1700236800000,"endTime":1701360000000,"background":"","menu":"","mica":""} +/// activityColors : {"enable":true,"startTime":1700236800000,"endTime":1701360000000,"background":"#290859","menu":"#310666","mica":"#270452"} class AppVersionData { AppVersionData({ @@ -57,9 +57,9 @@ class AppVersionData { /// enable : true /// startTime : 1700236800000 /// endTime : 1701360000000 -/// background : "" -/// menu : "" -/// mica : "" +/// background : "#290859" +/// menu : "#310666" +/// mica : "#270452" class ActivityColors { ActivityColors({ @@ -79,8 +79,8 @@ class ActivityColors { mica = json['mica']; } bool? enable; - num? startTime; - num? endTime; + int? startTime; + int? endTime; String? background; String? menu; String? mica; diff --git a/lib/global_ui_model.dart b/lib/global_ui_model.dart index bdee570..e9764fc 100644 --- a/lib/global_ui_model.dart +++ b/lib/global_ui_model.dart @@ -1,11 +1,12 @@ // ignore_for_file: use_build_context_synchronously +import 'dart:async'; import 'dart:io'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:hexcolor/hexcolor.dart'; import 'package:hive/hive.dart'; -import 'api/api.dart'; import 'base/ui_model.dart'; import 'common/conf.dart'; import 'common/helper/system_helper.dart'; @@ -16,16 +17,13 @@ final globalUIModel = AppGlobalUIModel(); final globalUIModelProvider = ChangeNotifierProvider((ref) => globalUIModel); class AppGlobalUIModel extends BaseUIModel { + Timer? activityThemeColorTimer; - String colorBackground = "#132431"; - String colorMenu = "#122D42"; - String colorMica = "#0A3142"; - - Future checkUpdate(BuildContext context, {bool init = true}) async { + Future doCheckUpdate(BuildContext context, {bool init = true}) async { if (AppConf.isMSE) return true; if (!init) { try { - AppConf.networkVersionData = await Api.getAppVersion(); + await AppConf.checkUpdate(); } catch (_) {} } await Future.delayed(const Duration(milliseconds: 100)); @@ -75,4 +73,45 @@ class AppGlobalUIModel extends BaseUIModel { await Future.delayed(const Duration(seconds: 2)); exit(0); } + + checkActivityThemeColor() { + if (activityThemeColorTimer != null) { + activityThemeColorTimer?.cancel(); + activityThemeColorTimer = null; + } + if (AppConf.networkVersionData == null || + AppConf.networkVersionData?.activityColors?.enable != true) return; + + final startTime = AppConf.networkVersionData!.activityColors?.startTime; + final endTime = AppConf.networkVersionData!.activityColors?.endTime; + if (startTime == null || endTime == null) return; + final now = DateTime.now().millisecondsSinceEpoch; + + dPrint("now == $now start == $startTime end == $endTime"); + if (now < startTime) { + activityThemeColorTimer = Timer( + Duration(milliseconds: startTime - now), checkActivityThemeColor); + dPrint("start Timer ...."); + } else if (now >= startTime && now <= endTime) { + dPrint("update Color ...."); + // update Color + final colorCfg = AppConf.networkVersionData!.activityColors; + AppConf.colorBackground = + HexColor(colorCfg?.background ?? "#132431").withOpacity(.75); + AppConf.colorMenu = + HexColor(colorCfg?.menu ?? "#132431").withOpacity(.95); + AppConf.colorMica = HexColor(colorCfg?.mica ?? "#0A3142"); + notifyListeners(); + // wait for end + activityThemeColorTimer = + Timer(Duration(milliseconds: endTime - now), checkActivityThemeColor); + } else { + dPrint("reset Color ...."); + AppConf.colorBackground = HexColor("#132431").withOpacity(.75); + AppConf.colorMenu = HexColor("#132431").withOpacity(.95); + AppConf.colorMica = HexColor("#0A3142"); + notifyListeners(); + } + notifyListeners(); + } } diff --git a/lib/main.dart b/lib/main.dart index 9320d07..00ac9af 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,5 @@ import 'package:desktop_webview_window/desktop_webview_window.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:hexcolor/hexcolor.dart'; import 'package:starcitizen_doctor/base/ui_model.dart'; import 'package:starcitizen_doctor/common/conf.dart'; import 'package:starcitizen_doctor/ui/index_ui_model.dart'; @@ -31,16 +30,14 @@ class AppUI extends BaseUI { title: "StarCitizen Doctor", restorationScopeId: "Doctor", themeMode: ThemeMode.dark, - // theme: FluentThemeData(brightness: Brightness.light), - darkTheme: FluentThemeData( + theme: FluentThemeData( brightness: Brightness.dark, fontFamily: "SourceHanSansCN-Regular", navigationPaneTheme: NavigationPaneThemeData( - backgroundColor: - HexColor(globalUIModel.colorBackground).withOpacity(.75), + backgroundColor: AppConf.colorBackground, ), - menuColor: HexColor(globalUIModel.colorMenu).withOpacity(.95), - micaBackgroundColor: HexColor(globalUIModel.colorMica), + menuColor: AppConf.colorMenu, + micaBackgroundColor: AppConf.colorMica, ), debugShowCheckedModeBanner: false, home: BaseUIContainer( @@ -58,7 +55,6 @@ class WindowButtons extends StatelessWidget { @override Widget build(BuildContext context) { final FluentThemeData theme = FluentTheme.of(context); - return SizedBox( width: 138, height: 50, diff --git a/lib/ui/about/about_ui_model.dart b/lib/ui/about/about_ui_model.dart index 7df94e9..7859af2 100644 --- a/lib/ui/about/about_ui_model.dart +++ b/lib/ui/about/about_ui_model.dart @@ -9,7 +9,7 @@ class AboutUIModel extends BaseUIModel { launchUrlString("ms-windows-store://pdp/?productid=9NF3SWFWNKL1"); return; } - final hasUpdate = await globalUIModel.checkUpdate(context!); + final hasUpdate = await globalUIModel.doCheckUpdate(context!); if (!hasUpdate) { if (mounted) showToast(context!, "已是最新版本"); } diff --git a/lib/ui/index_ui_model.dart b/lib/ui/index_ui_model.dart index b96d3fc..9e1a73a 100644 --- a/lib/ui/index_ui_model.dart +++ b/lib/ui/index_ui_model.dart @@ -17,7 +17,7 @@ class IndexUIModel extends BaseUIModel { void initModel() { _checkRunTime(); Future.delayed(const Duration(milliseconds: 300)) - .then((value) => globalUIModel.checkUpdate(context!)); + .then((value) => globalUIModel.doCheckUpdate(context!)); super.initModel(); }