优化节点列表拉取可能存在失败的可能
Build Android APK / 编译 libcore.aar (push) Has been cancelled
Build Multi-Platform / 编译 libcore (iOS/tvOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Android) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (macOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Linux) (push) Has been cancelled
Build Windows / 编译 libcore (Windows) (push) Has been cancelled
Build Windows / build (push) Has been cancelled
Build Android APK / 编译 Android APK (release) (push) Has been cancelled
Build Android APK / 创建 GitHub Release (push) Has been cancelled
Build Multi-Platform / 构建 Android APK (push) Has been cancelled
Build Multi-Platform / 构建 macOS (push) Has been cancelled
Build Multi-Platform / 构建 Linux (push) Has been cancelled
Build Multi-Platform / 构建 iOS (push) Has been cancelled
Build Multi-Platform / 创建 Release (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Windows) (push) Has been cancelled
Build Multi-Platform / 构建 Windows (push) Has been cancelled

(cherry picked from commit f59e70ed8b9084d29f792280d94f1c49719842a1)
This commit is contained in:
2025-11-04 01:07:24 -08:00
committed by speakeloudest
parent 6131a80b2c
commit 4fbdb331d4
2 changed files with 106 additions and 11 deletions
+37 -6
View File
@@ -14,6 +14,7 @@ import 'package:kaer_with_panels/app/localization/kr_language_utils.dart';
import 'package:kaer_with_panels/app/utils/kr_common_util.dart';
import 'package:kaer_with_panels/app/services/singbox_imp/kr_sing_box_imp.dart';
import 'package:kaer_with_panels/app/services/kr_site_config_service.dart';
import 'package:kaer_with_panels/singbox/model/singbox_status.dart';
// import 'package:crypto/crypto.dart';
// import 'package:encrypt/encrypt.dart';
@@ -79,14 +80,44 @@ class HttpUtil {
createHttpClient: () {
KRLogUtil.kr_i('📱 createHttpClient 回调被调用', tag: 'HttpUtil');
final client = HttpClient();
// ✅ 优化:智能代理回退逻辑
client.findProxy = (url) {
final proxyConfig = KRSingBoxImp.instance.kr_buildProxyRule();
KRLogUtil.kr_i(
'🔍 findProxy 被调用, url: $url, proxy: $proxyConfig',
tag: 'HttpUtil',
);
return proxyConfig;
try {
// 检查 SingBox 是否正在运行
final singBoxStatus = KRSingBoxImp.instance.kr_status;
final isProxyAvailable = singBoxStatus == SingboxStatus.started();
if (!isProxyAvailable) {
// 代理未运行,直接使用直连
KRLogUtil.kr_i(
'🔄 代理未运行,使用直连模式: $url',
tag: 'HttpUtil',
);
return 'DIRECT';
}
// 代理正在运行,使用代理配置
final proxyConfig = KRSingBoxImp.instance.kr_buildProxyRule();
KRLogUtil.kr_i(
'✅ 使用代理模式, url: $url, proxy: $proxyConfig',
tag: 'HttpUtil',
);
return proxyConfig;
} catch (e) {
// 发生异常时回退到直连
KRLogUtil.kr_w(
'⚠️ 代理配置异常,回退到直连: $e',
tag: 'HttpUtil',
);
return 'DIRECT';
}
};
// ✅ 优化:设置连接失败时的自动回退
client.connectionTimeout = const Duration(seconds: 10);
client.badCertificateCallback = (cert, host, port) => true;
return client;
},
);