feat: 修改代码冲突
Some checks failed
Build Windows / build (push) Has been cancelled
Build Windows / 编译 libcore (Windows) (20.15.1) (push) Has been cancelled

This commit is contained in:
speakeloudest 2025-11-09 22:43:57 -08:00
parent 33917e774d
commit a78b40c339
5 changed files with 135 additions and 100 deletions

5
.gitmodules vendored
View File

@ -1,3 +1,4 @@
[submodule "libcore"]
path = libcore
url = https://github.com/hiddify/hiddify-next-core
path = libcore
url = https://github.com/hiddify/hiddify-next-core
branch = main

View File

@ -105,8 +105,8 @@ android {
debugSymbolLevel 'FULL'
}
// VPN连接问题
minifyEnabled true
shrinkResources true
minifyEnabled false
shrinkResources false
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

View File

@ -133,11 +133,21 @@ class KRHomeController extends GetxController with WidgetsBindingObserver {
if (value != null) {
isQuickConnectEnabled.value = value;
//
await _storage.kr_saveBool(key: _quickConnectKey, value: value);
await _saveQuickConnectStatus(value);
KRLogUtil.kr_i('闪连状态已更新: $value', tag: 'QuickConnect');
}
}
//
Future<void> _saveQuickConnectStatus(bool enabled) async {
try {
await _storage.kr_saveBool(key: _quickConnectKey, value: enabled);
KRLogUtil.kr_i('闪连状态已保存到本地存储: $enabled', tag: 'QuickConnect');
} catch (e) {
KRLogUtil.kr_e('保存闪连状态失败: $e', tag: 'QuickConnect');
}
}
//
Future<void> _loadQuickConnectStatus() async {
try {
@ -1889,7 +1899,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver {
}
//
final nodeAddresses = <MapEntry<String, SocketAddress>>[];
final nodeAddresses = []; // <MapEntry<String, SocketAddress>>[];
for (final node in testableNodes) {
//
@ -1897,7 +1907,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver {
String host = node.serverAddr;
int port = 0;
// config中获取端口
/*// config中获取端口
if (node.config.containsKey('server_port')) {
port = node.config['server_port'] as int;
} else if (node.config.containsKey('port')) {
@ -1914,7 +1924,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver {
KRLogUtil.kr_w('⚠️ 节点 ${node.tag} 缺少地址或端口信息', tag: 'HomeController');
//
node.urlTestDelay.value = 65535;
}
}*/
} catch (e) {
KRLogUtil.kr_e('❌ 解析节点 ${node.tag} 配置失败: $e', tag: 'HomeController');
node.urlTestDelay.value = 65535;
@ -1932,7 +1942,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver {
final results = await KRLatencyTester.testMultipleNodes(
nodes: nodeAddresses,
concurrency: 10, // 10
timeout: 5000, // 5
timeout: const Duration(seconds: 5),
);
//

View File

@ -285,7 +285,7 @@ class KRSplashController extends GetxController {
KRLogUtil.kr_e('⏱️ 初始化超时: $e', tag: 'SplashController');
print('⏱️ 初始化超时,直接跳转到主页');
//
// Get.offAllNamed(Routes.KR_MAIN);
// Get.offAllNamed(Routes.KR_HOME);
HIDialog.show(
message: '初始化超时,请检查网络或重试',
confirmText: '重试',
@ -484,7 +484,7 @@ class KRSplashController extends GetxController {
_initLog.logWarning('网络权限检查失败或超时,执行降级初始化', tag: 'Init');
KRLogUtil.kr_w('⚠️ 网络权限检查失败或超时,执行降级初始化', tag: 'SplashController');
await _executeMinimalInitialization();
Get.offAllNamed(Routes.KR_MAIN);
Get.offAllNamed(Routes.KR_HOME);
return;
}
@ -493,7 +493,7 @@ class KRSplashController extends GetxController {
_initLog.logError('网络权限检查异常,执行降级初始化', tag: 'Init', error: e);
KRLogUtil.kr_w('⚠️ 网络权限检查异常: $e,执行降级初始化', tag: 'SplashController');
await _executeMinimalInitialization();
Get.offAllNamed(Routes.KR_MAIN);
Get.offAllNamed(Routes.KR_HOME);
return;
}
} else {
@ -582,7 +582,7 @@ class KRSplashController extends GetxController {
_initLog.logError('启动页初始化异常,执行降级策略', tag: 'Continue', error: e);
KRLogUtil.kr_w('⚠️ 启动页初始化异常,执行降级策略: $e', tag: 'SplashController');
await _executeMinimalInitialization();
Get.offAllNamed(Routes.KR_MAIN);
Get.offAllNamed(Routes.KR_HOME);
}
}
@ -726,7 +726,7 @@ class KRSplashController extends GetxController {
kr_isLoading.value = false;
//
Get.offAllNamed(Routes.KR_MAIN);
Get.offAllNamed(Routes.KR_HOME);
}
/// 🔧 1.1DEBUG模式专用

View File

@ -1,127 +1,151 @@
import 'dart:io';
import 'dart:async';
import 'package:kaer_with_panels/app/utils/kr_log_util.dart';
import 'kr_log_util.dart';
///
/// TCP
///
class KRLatencyTester {
///
///
/// :
/// - host:
/// - port:
/// - timeout:
///
/// :
/// - 65535
static Future<int> testNode({
/// TCP
/// 65535
static Future<int> testTcpLatency({
required String host,
required int port,
int timeout = 5000,
Duration timeout = const Duration(seconds: 5),
}) async {
Socket? socket;
final stopwatch = Stopwatch();
try {
final stopwatch = Stopwatch()..start();
final socket = await Socket.connect(
KRLogUtil.kr_i('🔌 开始测试: $host:$port', tag: 'LatencyTester');
stopwatch.start();
// TCP
socket = await Socket.connect(
host,
port,
timeout: Duration(milliseconds: timeout),
).timeout(Duration(milliseconds: timeout));
timeout: timeout,
);
stopwatch.stop();
//
await socket.close();
socket.destroy();
final latency = stopwatch.elapsedMilliseconds;
KRLogUtil.kr_i('✅ 延迟测试成功: $host:$port = ${latency}ms', tag: 'KRLatencyTester');
KRLogUtil.kr_i('✅ 测试成功: $host:$port - ${latency}ms', tag: 'LatencyTester');
return latency;
} on SocketException catch (e) {
stopwatch.stop();
KRLogUtil.kr_w('❌ 连接失败: $host:$port - ${e.message}', tag: 'LatencyTester');
return 65535;
} on TimeoutException catch (e) {
stopwatch.stop();
KRLogUtil.kr_w('⏱️ 连接超时: $host:$port - $e', tag: 'LatencyTester');
return 65535;
} catch (e) {
KRLogUtil.kr_w('❌ 延迟测试失败: $host:$port - $e', tag: 'KRLatencyTester');
return 65535; //
stopwatch.stop();
KRLogUtil.kr_e('❌ 测试异常: $host:$port - $e', tag: 'LatencyTester');
return 65535;
} finally {
//
try {
await socket?.close();
} catch (e) {
//
}
}
}
///
///
/// :
/// - nodes: [{"host": "example.com", "port": 443}]
/// - concurrency:
/// - timeout:
///
/// :
/// - "host:port"
///
/// Map<tag, ms>
static Future<Map<String, int>> testMultipleNodes({
required List<MapEntry<String, SocketAddress>> nodes,
int concurrency = 10,
int timeout = 5000,
int concurrency = 10, //
Duration timeout = const Duration(seconds: 5),
}) async {
final results = <String, int>{};
final semaphore = Completer<void>();
var activeCount = 0;
var completedCount = 0;
final List<List<MapEntry<String, SocketAddress>>> batches = [];
KRLogUtil.kr_i('🚀 开始批量延迟测试,共 ${nodes.length} 个节点,并发数: $concurrency', tag: 'KRLatencyTester');
//
for (int i = 0; i < nodes.length; i += concurrency) {
batches.add(
nodes.sublist(i, i + concurrency > nodes.length ? nodes.length : i + concurrency)
);
}
Future<void> processNode(MapEntry<String, SocketAddress> node) async {
try {
final host = node.value.address;
final port = node.value.port;
final key = node.key;
final latency = await testNode(
host: host,
port: port,
KRLogUtil.kr_i('📊 开始批量测试: ${nodes.length} 个节点,分 ${batches.length} 批,每批 $concurrency', tag: 'LatencyTester');
int completedCount = 0;
//
for (int batchIndex = 0; batchIndex < batches.length; batchIndex++) {
final batch = batches[batchIndex];
KRLogUtil.kr_i('📦 测试第 ${batchIndex + 1}/${batches.length} 批(${batch.length} 个节点)', tag: 'LatencyTester');
//
final futures = batch.map((node) async {
final tag = node.key;
final address = node.value;
final latency = await testTcpLatency(
host: address.host,
port: address.port,
timeout: timeout,
);
results[key] = latency;
} catch (e) {
results[node.key] = 65535;
KRLogUtil.kr_e('❌ 节点测试异常: ${node.key} - $e', tag: 'KRLatencyTester');
} finally {
completedCount++;
activeCount--;
if (completedCount >= nodes.length) {
semaphore.complete();
if (completedCount % 5 == 0 || completedCount == nodes.length) {
KRLogUtil.kr_i('📈 测试进度: $completedCount/${nodes.length}', tag: 'LatencyTester');
}
}
}
//
for (var i = 0; i < nodes.length; i += concurrency) {
final batch = nodes.skip(i).take(concurrency);
for (final node in batch) {
activeCount++;
processNode(node);
}
return MapEntry(tag, latency);
}).toList();
//
if (i + concurrency < nodes.length) {
await Future.delayed(Duration(milliseconds: 100));
final batchResults = await Future.wait(futures);
//
for (final result in batchResults) {
results[result.key] = result.value;
}
}
//
final successCount = results.values.where((latency) => latency < 65535).length;
final failCount = results.length - successCount;
KRLogUtil.kr_i('✅ 批量测试完成', tag: 'LatencyTester');
KRLogUtil.kr_i('📊 成功: $successCount, 失败: $failCount', tag: 'LatencyTester');
// 3
final successNodes = results.entries
.where((e) => e.value < 65535)
.toList()
..sort((a, b) => a.value.compareTo(b.value));
if (successNodes.isNotEmpty) {
KRLogUtil.kr_i('🏆 延迟最低的前3个节点:', tag: 'LatencyTester');
for (int i = 0; i < 3 && i < successNodes.length; i++) {
KRLogUtil.kr_i(' ${i + 1}. ${successNodes[i].key}: ${successNodes[i].value}ms', tag: 'LatencyTester');
}
}
//
await semaphore.future;
KRLogUtil.kr_i('✅ 批量延迟测试完成,成功: ${results.length}', tag: 'KRLatencyTester');
return results;
}
}
/// Socket
///
///
class SocketAddress {
final String address;
final String host;
final int port;
SocketAddress(this.address, this.port);
SocketAddress(this.host, this.port);
@override
String toString() => '$address:$port';
}
String toString() => '$host:$port';
}