1. /lib/app/common/app_config.dart

- P0: 限制递归重试次数(最多5次)
    - P1: 减少超时时间(3s→2s, 6s→4s)
    - P1: 移除重复域名配置
  2.  /lib/app/services/kr_site_config_service.dart
    - P1: 减少网络超时(10s→5s)
  3.  /lib/app/modules/kr_splash/controllers/kr_splash_controller.dart
    - P0: 总体超时保护(30秒)
    - P2: 非阻塞初始化
    - P2: 后台任务超时保护(网站配置10s, 设备登录8s)
    - P2: 完善错误处理(区分超时/网络/HTTP错误)
    - P3: 跳过初始化功能
  4.  /lib/app/modules/kr_splash/views/kr_splash_view.dart
    - P3: 添加"跳过"按钮

(cherry picked from commit 0a9fe429919fe9ae85b7769df123b72d7e33c6b1)
This commit is contained in:
2025-10-31 01:50:25 -07:00
committed by speakeloudest
parent c5715f77e2
commit 442ea458b7
4 changed files with 282 additions and 123 deletions
+27 -3
View File
@@ -53,8 +53,9 @@ class KRDomain {
static Timer? _retryTimer;
static const int kr_retryInterval = 2; // 基础重试间隔(秒)
static const int kr_maxRetryCount = 2; // 最大重试次数
static const int kr_domainTimeout = 3; // 域名检测超时时间(秒)
static const int kr_totalTimeout = 6; // 总体超时时间(秒)
// 🔧 P1修复:减少域名检测超时时间
static const int kr_domainTimeout = 2; // 域名检测超时时间(秒)3→2
static const int kr_totalTimeout = 4; // 总体超时时间(秒)6→4
static Set<String> _triedDomains = {}; // 已尝试过的域名集合
static Map<String, int> _domainResponseTimes = {}; // 域名响应时间记录
static Map<String, DateTime> _domainLastCheck = {}; // 域名最后检测时间
@@ -1057,6 +1058,7 @@ class AppConfig {
/// 请求域名地址
/// 基础url
///
// static String baseUrl = "http://103.112.98.72:8088";
/// 请求域名地址
@@ -1146,9 +1148,23 @@ class AppConfig {
Future<void> _startAutoRetry(Future<void> Function()? onSuccess) async {
_retryTimer?.cancel();
int currentRetryCount = 0;
// 🔧 P0修复:添加总体尝试次数限制,防止无限递归
int totalAttempts = 0;
const int maxTotalAttempts = 5; // 最多5次尝试(包括域名切换后的重试)
Future<void> executeConfigRequest() async {
try {
// 🔧 P0修复:检查总体尝试次数
totalAttempts++;
if (totalAttempts > maxTotalAttempts) {
KRLogUtil.kr_e('❌ 超过最大总尝试次数($maxTotalAttempts),停止重试', tag: 'AppConfig');
// 使用默认配置继续启动
if (onSuccess != null) {
await onSuccess();
}
return;
}
// 检查是否超过最大重试次数
if (currentRetryCount >= kr_maxRetryCount) {
KRLogUtil.kr_w('达到最大重试次数,尝试使用备用域名', tag: 'AppConfig');
@@ -1158,8 +1174,16 @@ class AppConfig {
KRDomain.kr_currentDomain = newDomain;
await KRDomain.kr_saveCurrentDomain();
KRLogUtil.kr_i('✅ 最终切换到备用域名: $newDomain', tag: 'AppConfig');
// 重置当前重试计数,但保留总尝试次数
currentRetryCount = 0;
// 继续重试配置请求
await executeConfigRequest();
} else {
KRLogUtil.kr_e('❌ 备用域名切换失败,使用默认配置继续', tag: 'AppConfig');
// 使用默认配置继续启动
if (onSuccess != null) {
await onSuccess();
}
}
return;
}