2023-10-09 09:32:07 +08:00
|
|
|
|
// ignore_for_file: use_build_context_synchronously
|
|
|
|
|
|
2023-11-11 01:18:30 +08:00
|
|
|
|
import 'dart:async';
|
2023-11-06 22:23:06 +08:00
|
|
|
|
|
2023-10-09 09:32:07 +08:00
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2023-11-11 01:18:30 +08:00
|
|
|
|
import 'package:hexcolor/hexcolor.dart';
|
2023-10-09 09:32:07 +08:00
|
|
|
|
|
|
|
|
|
import 'base/ui_model.dart';
|
2024-01-29 20:44:00 +08:00
|
|
|
|
import 'common/conf/app_conf.dart';
|
2023-10-09 09:32:07 +08:00
|
|
|
|
import 'ui/settings/upgrade_dialog_ui.dart';
|
|
|
|
|
import 'ui/settings/upgrade_dialog_ui_model.dart';
|
|
|
|
|
|
|
|
|
|
final globalUIModel = AppGlobalUIModel();
|
|
|
|
|
final globalUIModelProvider = ChangeNotifierProvider((ref) => globalUIModel);
|
|
|
|
|
|
|
|
|
|
class AppGlobalUIModel extends BaseUIModel {
|
2023-11-11 01:18:30 +08:00
|
|
|
|
Timer? activityThemeColorTimer;
|
2023-11-10 22:56:55 +08:00
|
|
|
|
|
2024-01-14 20:47:15 +08:00
|
|
|
|
Future<String?> getRunningGameUser() async {
|
2024-01-13 17:29:41 +08:00
|
|
|
|
await Future.delayed(const Duration(milliseconds: 300));
|
|
|
|
|
|
|
|
|
|
///TODO 实现获取运行中用户名
|
|
|
|
|
return "xkeyC";
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-11 01:18:30 +08:00
|
|
|
|
Future<bool> doCheckUpdate(BuildContext context, {bool init = true}) async {
|
2023-12-09 12:49:08 +08:00
|
|
|
|
dynamic checkUpdateError;
|
2023-10-09 09:32:07 +08:00
|
|
|
|
if (!init) {
|
|
|
|
|
try {
|
2023-11-11 01:18:30 +08:00
|
|
|
|
await AppConf.checkUpdate();
|
2023-12-09 12:49:08 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
checkUpdateError = e;
|
|
|
|
|
}
|
2023-10-09 09:32:07 +08:00
|
|
|
|
}
|
|
|
|
|
await Future.delayed(const Duration(milliseconds: 100));
|
|
|
|
|
if (AppConf.networkVersionData == null) {
|
|
|
|
|
showToast(context,
|
2024-02-16 22:47:06 +08:00
|
|
|
|
"网络异常!\n这可能是您的网络环境存在DNS污染,请尝试更换DNS。\n或服务器正在维护或遭受攻击,稍后再试。 \n进入离线模式... \n\n请谨慎在离线模式中使用。 \n当前版本构建日期:${AppConf.appVersionDate}\n QQ群:940696487 \n错误信息:$checkUpdateError");
|
2023-10-09 09:32:07 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-11-11 01:41:06 +08:00
|
|
|
|
final lastVersion = AppConf.isMSE
|
|
|
|
|
? AppConf.networkVersionData?.mSELastVersionCode
|
|
|
|
|
: AppConf.networkVersionData?.lastVersionCode;
|
|
|
|
|
if ((lastVersion ?? 0) > AppConf.appVersionCode) {
|
2023-10-09 09:32:07 +08:00
|
|
|
|
// need update
|
|
|
|
|
final r = await showDialog(
|
|
|
|
|
dismissWithEsc: false,
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) => BaseUIContainer(
|
|
|
|
|
uiCreate: () => UpgradeDialogUI(),
|
|
|
|
|
modelCreate: () => UpgradeDialogUIModel()));
|
|
|
|
|
if (r != true) {
|
|
|
|
|
showToast(context, "获取更新信息失败,请稍后重试。");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-11-06 22:23:06 +08:00
|
|
|
|
|
2023-11-11 01:18:30 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
2023-10-09 09:32:07 +08:00
|
|
|
|
}
|