feat: 修改兼容

This commit is contained in:
speakeloudest 2025-11-20 00:51:14 -08:00
parent 8fd742a688
commit 89d13e6237
2 changed files with 107 additions and 20 deletions

View File

@ -436,7 +436,7 @@ class HINodeListView extends GetView<HINodeListController> {
print('🎯 检测到auto组节点获取最快节点信息');
final autoNodeInfo = controller.homeController.kr_getCountryAutoSelectedNode(item.country);
print('📊 _kr_buildNodeListItem获取auto最快节点: $autoNodeInfo');
displayDelay = autoNodeInfo?['delay'] ?? 3000;
displayDelay = autoNodeInfo?['delay'] ?? 0;
print('✅ _kr_buildNodeListItem使用auto最快节点延迟: $displayDelay');
} else {
//

View File

@ -12,6 +12,7 @@ import 'package:kaer_with_panels/singbox/service/singbox_service.dart';
import 'package:kaer_with_panels/singbox/service/singbox_service_provider.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as p;
import 'package:device_info_plus/device_info_plus.dart';
import '../../../core/model/directories.dart';
import '../../../singbox/model/singbox_config_option.dart';
@ -112,6 +113,62 @@ class KRSingBoxImp {
/// Futuresingle-flight
Future<void>? _kr_initFuture;
/// Android模拟器
bool _kr_isAndroidEmulator = false;
///
///
/// - Android
/// - brand/model/product/manufacturer
/// `_kr_isAndroidEmulator`
Future<void> _kr_detectEmulator() async {
try {
if (!Platform.isAndroid) {
_kr_isAndroidEmulator = false;
return;
}
final info = await DeviceInfoPlugin().androidInfo;
final brand = (info.brand ?? '').toLowerCase();
final model = (info.model ?? '').toLowerCase();
final product = (info.product ?? '').toLowerCase();
final manufacturer = (info.manufacturer ?? '').toLowerCase();
final device = (info.device ?? '').toLowerCase();
bool containsAny(String s, List<String> keys) => keys.any((k) => s.contains(k));
final indicators = <bool>[
containsAny(brand, [
'generic', 'unknown', 'google', 'vbox', 'virtualbox',
'bluestacks', 'nox', 'ldplayer', 'genymotion', 'mumu', 'netease', 'leidian'
]),
containsAny(model, [
'emulator', 'sdk', 'sdk_gphone', 'google_sdk', 'android sdk built for x86',
'bluestacks', 'genymotion', 'nox', 'ldplayer', 'mumu'
]),
containsAny(product, [
'sdk', 'google_sdk', 'sdk_gphone', 'emulator', 'vbox', 'virtualbox'
]),
containsAny(manufacturer, [
'genymotion', 'unknown', 'bluestacks', 'nox', 'ld', 'netease', 'mumu'
]),
containsAny(device, [
'emulator', 'generic', 'vbox', 'virtualbox', 'sdk'
]),
];
_kr_isAndroidEmulator = indicators.any((v) => v);
KRLogUtil.kr_i(
'🔍 Android 模拟器检测: ${_kr_isAndroidEmulator ? '是模拟器' : '非模拟器'}'
' (brand=$brand, model=$model, product=$product, manufacturer=$manufacturer, device=$device)',
tag: 'SingBox',
);
} catch (e) {
_kr_isAndroidEmulator = false;
KRLogUtil.kr_w('⚠️ 模拟器检测失败,按真机处理: $e', tag: 'SingBox');
}
}
///
bool get kr_isProxyReady => kr_status.value is SingboxStarted;
@ -167,6 +224,9 @@ class KRSingBoxImp {
await KRCountryUtil.kr_init();
KRLogUtil.kr_i('国家工具初始化完成');
// Android模拟器
await _kr_detectEmulator();
final oOption = SingboxConfigOption.fromJson(_getConfigOption());
KRLogUtil.kr_i('配置选项初始化完成');
@ -555,9 +615,11 @@ class KRSingBoxImp {
"log-level": "info", // 使 info warn
"resolve-destination": false,
"ipv6-mode": "ipv4_only", // hiddify-app: 使 IPv4 (: ipv4_only, prefer_ipv4, prefer_ipv6, ipv6_only)
"remote-dns-address": "https://dns.google/dns-query", // 使 Google DoH DNS
"remote-dns-address": _kr_isAndroidEmulator
? "local"
: "https://dns.google/dns-query",
"remote-dns-domain-strategy": "prefer_ipv4",
"direct-dns-address": "local", // 使 DNS
"direct-dns-address": "local",
"direct-dns-domain-strategy": "prefer_ipv4",
"mixed-port": kr_port,
"tproxy-port": kr_port,
@ -645,6 +707,47 @@ class KRSingBoxImp {
return op;
}
/// DNS
///
/// - 使 DoH + DNSfinal
/// - 使 DNSfinal DNS
/// Sing-box `dns` Map
Map<String, dynamic> _kr_buildDnsConfig() {
if (_kr_isAndroidEmulator) {
KRLogUtil.kr_i('🛡️ 模拟器兼容模式:强制使用系统 DNS', tag: 'SingBox');
return {
"servers": [
{
"tag": "dns-direct",
"address": "local",
"detour": "direct"
}
],
"rules": [],
"final": "dns-direct",
"strategy": "prefer_ipv4"
};
}
return {
"servers": [
{
"tag": "dns-remote",
"address": "https://1.1.1.1/dns-query",
"address_resolver": "dns-direct"
},
{
"tag": "dns-direct",
"address": "local",
"detour": "direct"
}
],
"rules": _kr_buildDnsRules(),
"final": "dns-remote",
"strategy": "prefer_ipv4"
};
}
///
/// hiddify-app: libcore UI
void _kr_subscribeToStatus() {
@ -1150,23 +1253,7 @@ class KRSingBoxImp {
"level": "debug",
"timestamp": true
},
"dns": {
"servers": [
{
"tag": "dns-remote",
"address": "https://1.1.1.1/dns-query",
"address_resolver": "dns-direct"
},
{
"tag": "dns-direct",
"address": "local",
"detour": "direct"
}
],
"rules": _kr_buildDnsRules(), // 使 DNS
"final": "dns-remote",
"strategy": "prefer_ipv4"
},
"dns": _kr_buildDnsConfig(),
"inbounds": [
{
"type": "tun",