优化部分安卓机型可能存在连接超时等问题新增日志排查
(cherry picked from commit e0fcc27f28f27321a49115df86507e3ac55e8ef8)
This commit is contained in:
@@ -28,7 +28,7 @@ import 'package:kaer_with_panels/app/modules/kr_home/controllers/kr_home_control
|
||||
import 'package:kaer_with_panels/app/modules/kr_home/models/kr_home_views_status.dart';
|
||||
import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
// import 'package:kaer_with_panels/app/utils/kr_init_log_collector.dart';
|
||||
import 'package:kaer_with_panels/app/utils/kr_init_log_collector.dart';
|
||||
|
||||
class KRSplashController extends GetxController {
|
||||
// 🔧 新增:初始化日志收集器
|
||||
@@ -311,6 +311,115 @@ class KRSplashController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
/// 🔧 Android 15 新增:最小化初始化(降级策略)
|
||||
/// 确保即使网络失败,应用也能启动到可用状态
|
||||
Future<void> _executeMinimalInitialization() async {
|
||||
try {
|
||||
_initLog.logPhaseStart('降级初始化(Minimal Initialization)');
|
||||
_initLog.logWarning('网络初始化失败,执行降级策略', tag: 'Splash');
|
||||
KRLogUtil.kr_i('🛡️ 执行最小化初始化(降级模式)', tag: 'SplashController');
|
||||
if (kDebugMode) {
|
||||
print('🛡️ 执行最小化初始化(降级模式)');
|
||||
}
|
||||
|
||||
// 1. 设置默认域名(确保应用有可用域名)
|
||||
try {
|
||||
_initLog.log('步骤1: 设置默认域名', tag: 'Minimal');
|
||||
if (KRDomain.kr_currentDomain.isEmpty && KRDomain.kr_baseDomains.isNotEmpty) {
|
||||
KRDomain.kr_currentDomain = KRDomain.kr_baseDomains[0];
|
||||
_initLog.logSuccess('设置默认域名: ${KRDomain.kr_currentDomain}', tag: 'Minimal');
|
||||
KRLogUtil.kr_i('✅ 设置默认域名: ${KRDomain.kr_currentDomain}', tag: 'SplashController');
|
||||
if (kDebugMode) {
|
||||
print('✅ 设置默认域名: ${KRDomain.kr_currentDomain}');
|
||||
}
|
||||
} else {
|
||||
_initLog.log('当前域名: ${KRDomain.kr_currentDomain}', tag: 'Minimal');
|
||||
}
|
||||
} catch (e) {
|
||||
_initLog.logError('设置默认域名失败', tag: 'Minimal', error: e);
|
||||
KRLogUtil.kr_w('⚠️ 设置默认域名失败: $e', tag: 'SplashController');
|
||||
}
|
||||
|
||||
// 2. 初始化 SingBox(核心功能,不依赖网络)
|
||||
try {
|
||||
_initLog.log('步骤2: 初始化 SingBox', tag: 'Minimal');
|
||||
await KRSingBoxImp.instance.init().timeout(
|
||||
const Duration(seconds: 3),
|
||||
onTimeout: () {
|
||||
_initLog.logWarning('SingBox 初始化超时(3秒)', tag: 'Minimal');
|
||||
KRLogUtil.kr_w('SingBox 初始化超时', tag: 'SplashController');
|
||||
if (kDebugMode) {
|
||||
print('⏱️ SingBox 初始化超时');
|
||||
}
|
||||
},
|
||||
);
|
||||
_initLog.logSuccess('SingBox 初始化完成', tag: 'Minimal');
|
||||
KRLogUtil.kr_i('✅ SingBox 初始化完成', tag: 'SplashController');
|
||||
if (kDebugMode) {
|
||||
print('✅ SingBox 初始化完成');
|
||||
}
|
||||
} catch (e) {
|
||||
_initLog.logError('SingBox 初始化失败', tag: 'Minimal', error: e);
|
||||
KRLogUtil.kr_w('⚠️ SingBox 初始化失败: $e', tag: 'SplashController');
|
||||
if (kDebugMode) {
|
||||
print('⚠️ SingBox 初始化失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 尝试加载本地用户信息(不依赖网络)
|
||||
try {
|
||||
_initLog.log('步骤3: 加载本地用户信息', tag: 'Minimal');
|
||||
await KRAppRunData.getInstance().kr_initializeUserInfo().timeout(
|
||||
const Duration(seconds: 2),
|
||||
onTimeout: () {
|
||||
_initLog.logWarning('用户信息加载超时(2秒)', tag: 'Minimal');
|
||||
KRLogUtil.kr_w('用户信息加载超时', tag: 'SplashController');
|
||||
if (kDebugMode) {
|
||||
print('⏱️ 用户信息加载超时');
|
||||
}
|
||||
},
|
||||
);
|
||||
_initLog.logSuccess('本地用户信息加载完成', tag: 'Minimal');
|
||||
KRLogUtil.kr_i('✅ 本地用户信息加载完成', tag: 'SplashController');
|
||||
if (kDebugMode) {
|
||||
print('✅ 本地用户信息加载完成');
|
||||
}
|
||||
} catch (e) {
|
||||
_initLog.logError('用户信息加载失败', tag: 'Minimal', error: e);
|
||||
KRLogUtil.kr_w('⚠️ 用户信息加载失败: $e', tag: 'SplashController');
|
||||
if (kDebugMode) {
|
||||
print('⚠️ 用户信息加载失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
_initLog.logPhaseEnd('降级初始化(Minimal Initialization)', success: true);
|
||||
_initLog.log('应用将以降级模式启动,用户将看到基本UI', tag: 'Minimal');
|
||||
_initLog.log('预期显示:订阅卡片 + 连接选项', tag: 'Minimal');
|
||||
|
||||
KRLogUtil.kr_i('✅ 最小化初始化完成,应用将以降级模式启动', tag: 'SplashController');
|
||||
if (kDebugMode) {
|
||||
print('✅ 最小化初始化完成,应用将以降级模式启动');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print('📱 用户将看到基本UI(订阅卡片 + 连接选项)');
|
||||
}
|
||||
|
||||
// 🔧 最小化初始化也不关闭日志
|
||||
// await _initLog.finalize(); // ❌ 注释掉
|
||||
if (kDebugMode && _initLog.getLogFilePath() != null) {
|
||||
print('📁 初始化日志文件(保持打开): ${_initLog.getLogFilePath()}');
|
||||
}
|
||||
} catch (e) {
|
||||
_initLog.logError('最小化初始化也失败', tag: 'Minimal', error: e);
|
||||
KRLogUtil.kr_e('❌ 最小化初始化也失败: $e', tag: 'SplashController');
|
||||
if (kDebugMode) {
|
||||
print('❌ 最小化初始化也失败: $e');
|
||||
}
|
||||
// 即使降级初始化失败也不关闭日志
|
||||
// await _initLog.finalize(); // ❌ 注释掉
|
||||
}
|
||||
}
|
||||
|
||||
/// 处理错误并显示
|
||||
void _handleError(String title, String message) {
|
||||
kr_hasError.value = true;
|
||||
|
||||
Reference in New Issue
Block a user