This commit is contained in:
xkeyC 2023-11-11 01:18:30 +08:00
parent 6494c7971e
commit 7c833fe3ac
6 changed files with 71 additions and 25 deletions

View File

@ -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<void> _checkUpdate() async {
static Future<void> 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) {

View File

@ -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;

View File

@ -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<bool> checkUpdate(BuildContext context, {bool init = true}) async {
Future<bool> 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();
}
}

View File

@ -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,

View File

@ -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!, "已是最新版本");
}

View File

@ -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();
}