feat: 修改测试节点问题
Some checks failed
Build Android APK / 编译 libcore.aar (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 / 编译 libcore (iOS/tvOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Android) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Windows) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (macOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Linux) (push) Has been cancelled
Build Multi-Platform / 构建 Android APK (push) Has been cancelled
Build Multi-Platform / 构建 Windows (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 Windows / build (push) Has been cancelled
Build Windows / 编译 libcore (Windows) (push) Has been cancelled
Some checks failed
Build Android APK / 编译 libcore.aar (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 / 编译 libcore (iOS/tvOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Android) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Windows) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (macOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Linux) (push) Has been cancelled
Build Multi-Platform / 构建 Android APK (push) Has been cancelled
Build Multi-Platform / 构建 Windows (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 Windows / build (push) Has been cancelled
Build Windows / 编译 libcore (Windows) (push) Has been cancelled
This commit is contained in:
parent
445b1e0352
commit
b79ce2d15a
@ -27,7 +27,10 @@ class KROutboundItem {
|
||||
|
||||
/// URL
|
||||
String url = "";
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'KROutboundItem(tag: $tag, country: $country, delay: ${urlTestDelay.value}ms)';
|
||||
}
|
||||
/// 服务器类型
|
||||
|
||||
/// 构造函数,接受 KrNodeListItem 对象并初始化 KROutboundItem
|
||||
|
||||
@ -38,59 +38,6 @@ class HINodeListController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
/// 根据国家选择最快的节点
|
||||
void kr_selectFastestNodeByCountry(String country) {
|
||||
KRLogUtil.kr_i('开始为国家 $country 选择最快节点', tag: 'HINodeListController');
|
||||
|
||||
// 通知kr_home当前选择的国家
|
||||
homeController.setCurrentSelectedCountry(country);
|
||||
|
||||
// 查找国家分组
|
||||
final countryGroup = kr_subscribeService.countryOutboundList
|
||||
.firstWhereOrNull((group) => group.country == country);
|
||||
|
||||
if (countryGroup == null) {
|
||||
KRLogUtil.kr_w('未找到国家分组: $country', tag: 'HINodeListController');
|
||||
return;
|
||||
}
|
||||
|
||||
if (countryGroup.outboundList.isEmpty) {
|
||||
KRLogUtil.kr_w('国家 $country 的节点列表为空', tag: 'HINodeListController');
|
||||
return;
|
||||
}
|
||||
|
||||
// 查找延迟最小的有效节点
|
||||
String? fastestNodeTag;
|
||||
int minDelay = 65535;
|
||||
int validNodeCount = 0;
|
||||
|
||||
for (var node in countryGroup.outboundList) {
|
||||
final delay = node.urlTestDelay.value;
|
||||
|
||||
// 统计有效节点数量
|
||||
if (delay < 65535 && delay > 0) {
|
||||
validNodeCount++;
|
||||
|
||||
// 找到延迟更小的节点
|
||||
if (delay < minDelay) {
|
||||
minDelay = delay;
|
||||
fastestNodeTag = node.tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KRLogUtil.kr_i('国家 $country 内有 $validNodeCount 个有效节点可供切换', tag: 'HINodeListController');
|
||||
|
||||
// 选择最快的节点,如果没有有效延迟则选择第一个
|
||||
final selectedTag = fastestNodeTag ?? countryGroup.outboundList.first.tag;
|
||||
|
||||
KRLogUtil.kr_i('选择节点: $selectedTag (延迟: ${minDelay == 65535 ? "未知" : "${minDelay}ms"})',
|
||||
tag: 'HINodeListController');
|
||||
|
||||
// 调用homeController的选择节点方法
|
||||
homeController.kr_selectNode(selectedTag);
|
||||
}
|
||||
|
||||
/// 获取当前国家内的有效节点标签列表
|
||||
List<String> getValidNodesInCurrentCountry() {
|
||||
final country = homeController.currentSelectedCountry.value;
|
||||
|
||||
@ -39,20 +39,66 @@ class HINodeListView extends GetView<HINodeListController> {
|
||||
return _fakeDelays[item.tag] ?? 0;
|
||||
}
|
||||
|
||||
/// 获取分组内最快节点的延迟值(单位:ms)
|
||||
/// 如果列表为空,返回 0
|
||||
int getFastestNodeDelay(
|
||||
HINodeListController controller, List<KROutboundItem> outboundList) {
|
||||
if (outboundList.isEmpty) return 0;
|
||||
|
||||
int fastestDelay = _getDisplayDelay(controller, outboundList.first);
|
||||
|
||||
for (final item in outboundList.skip(1)) {
|
||||
final delay = _getDisplayDelay(controller, item);
|
||||
if (delay < fastestDelay) {
|
||||
fastestDelay = delay;
|
||||
}
|
||||
}
|
||||
|
||||
return fastestDelay;
|
||||
}
|
||||
|
||||
/// 找出延迟最低(最快)的节点对象
|
||||
KROutboundItem findFastestNode(List<KROutboundItem> outboundList) {
|
||||
if (outboundList.isEmpty) {
|
||||
throw ArgumentError('outboundList 不能为空');
|
||||
}
|
||||
|
||||
KROutboundItem fastest = outboundList.first;
|
||||
int fastestDelay = fastest.urlTestDelay.value;
|
||||
|
||||
for (final item in outboundList.skip(1)) {
|
||||
final delay = item.urlTestDelay.value;
|
||||
print('国家分组下的节点$delay');
|
||||
if (delay < fastestDelay) {
|
||||
fastest = item;
|
||||
fastestDelay = delay;
|
||||
}
|
||||
}
|
||||
|
||||
return fastest;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 1. 使用 Material 作为根组件,确保 InkWell 的水波纹效果正常
|
||||
// 并设置透明背景,让父组件的背景可以透出来
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
// child: _buildSubscribeList(context)
|
||||
child: _kr_buildRegionList(context)
|
||||
child: _buildSubscribeList(context)
|
||||
// child: _kr_buildRegionList(context)
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建国家/地区分组列表
|
||||
Widget _kr_buildRegionList(BuildContext context) {
|
||||
return Obx(() {
|
||||
// 自动触发延迟测试(仅在未连接状态下)
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!controller.homeController.kr_isConnected.value && !controller.homeController.kr_isLatency.value) {
|
||||
KRLogUtil.kr_i('🔄 节点列表显示 - 自动触发延迟测试', tag: 'HINodeListView');
|
||||
controller.homeController.kr_urlTest();
|
||||
}
|
||||
});
|
||||
return _kr_buildListContainer(
|
||||
context,
|
||||
child: ListView(
|
||||
@ -142,10 +188,15 @@ class HINodeListView extends GetView<HINodeListController> {
|
||||
...controller.kr_subscribeService.countryOutboundList.map((country) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
// 选择国家
|
||||
controller.homeController.kr_coutryText.value = country.country;
|
||||
// 自动选择这个国家下的节点延迟中最快的
|
||||
controller.kr_selectFastestNodeByCountry(country.country);
|
||||
final item = findFastestNode(country.outboundList);
|
||||
KRLogUtil.kr_i(item.tag);
|
||||
print('item${item.toString()}');
|
||||
controller.homeController.kr_selectNode(item.tag);
|
||||
controller.homeController.kr_currentListStatus.value =
|
||||
KRHomeViewsListStatus.kr_none;
|
||||
controller.homeController.kr_coutryText.value = country.country;
|
||||
|
||||
},
|
||||
child: _kr_buildCountryListItem(context, country: country),
|
||||
);
|
||||
@ -349,12 +400,6 @@ class HINodeListView extends GetView<HINodeListController> {
|
||||
Obx(() {
|
||||
// 2. 获取用于显示的延迟值
|
||||
final int delay = _getDisplayDelay(controller, item);
|
||||
// 3. 根据延迟值显示不同内容
|
||||
// if (delay <= 0) {
|
||||
// // 如果延迟为0或负数(初始状态或测试失败),则不显示
|
||||
// return const SizedBox.shrink();
|
||||
// }
|
||||
// 4. 显示延迟值,并添加 "ms" 单位
|
||||
return Text(
|
||||
'${delay}ms',
|
||||
style: KrAppTextStyle(
|
||||
@ -391,6 +436,18 @@ class HINodeListView extends GetView<HINodeListController> {
|
||||
|
||||
/// 构建国家列表项的UI
|
||||
Widget _kr_buildCountryListItem(BuildContext context, {required country}) {
|
||||
// 获取延迟颜色
|
||||
Color getLatencyColor(int delay) {
|
||||
if (delay == 0) {
|
||||
return Colors.transparent;
|
||||
} else if (delay < 500) {
|
||||
return krModernGreen;
|
||||
} else if (delay < 3000) {
|
||||
return Color(0xFFFFB700); // 使用更容易看清的黄色
|
||||
} else {
|
||||
return Colors.red;
|
||||
}
|
||||
}
|
||||
return Container(
|
||||
key: ValueKey(country),
|
||||
decoration: BoxDecoration(
|
||||
@ -413,6 +470,22 @@ class HINodeListView extends GetView<HINodeListController> {
|
||||
style: KrAppTextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white),
|
||||
),
|
||||
),
|
||||
Obx(() {
|
||||
final int delay = getFastestNodeDelay(controller, country.outboundList);
|
||||
return Text(
|
||||
delay == 0
|
||||
? ''
|
||||
: delay >= 3000
|
||||
? AppTranslations.kr_home.timeout
|
||||
: '${delay}ms',
|
||||
style: KrAppTextStyle(
|
||||
fontSize: 10,
|
||||
color: getLatencyColor(delay),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
);
|
||||
}),
|
||||
SizedBox(width: 12.w),
|
||||
Obx(() => controller.homeController.kr_coutryText.value == country.country
|
||||
? KrLocalImage(
|
||||
imageName: 'radio-active-icon',
|
||||
|
||||
@ -203,7 +203,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver {
|
||||
KRLogUtil.kr_i('开始执行闪连自动连接', tag: 'QuickConnect');
|
||||
|
||||
// 防止重复操作
|
||||
if (KRSingBoxImp.instance.kr_status == SingboxStarted) {
|
||||
if (KRSingBoxImp.instance.kr_status.value == SingboxStarted()) {
|
||||
KRLogUtil.kr_w('连接操作正在进行中,跳过自动连接', tag: 'QuickConnect');
|
||||
return;
|
||||
}
|
||||
@ -439,9 +439,6 @@ class KRHomeController extends GetxController with WidgetsBindingObserver {
|
||||
kr_cutTag.value = 'auto';
|
||||
kr_cutSeletedTag.value = 'auto';
|
||||
kr_currentNodeName.value = "auto";
|
||||
// 当订阅服务初始化成功后,检查闪连自动连接
|
||||
KRLogUtil.kr_i(
|
||||
'订阅服务初始化完成,检查闪连自动连接', tag: 'QuickConnect');
|
||||
if (kr_currentListStatus.value != KRHomeViewsListStatus.kr_none) {
|
||||
kr_currentListStatus.value = KRHomeViewsListStatus.kr_none;
|
||||
} else {
|
||||
@ -793,7 +790,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver {
|
||||
_kr_updateNodeLatency(element);
|
||||
kr_currentNodeName.value =
|
||||
kr_truncateText(element.selected, maxLength: 25);
|
||||
kr_moveToSelectedNode();
|
||||
// kr_moveToSelectedNode();
|
||||
}
|
||||
} catch (e) {
|
||||
KRLogUtil.kr_e('处理手动模式出错: $e', tag: 'HomeController');
|
||||
@ -858,7 +855,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver {
|
||||
|
||||
kr_currentNodeName.value =
|
||||
kr_truncateText("${item.selected}(auto)", maxLength: 25);
|
||||
kr_moveToSelectedNode();
|
||||
// kr_moveToSelectedNode();
|
||||
kr_updateConnectionInfo();
|
||||
break;
|
||||
} else {
|
||||
@ -889,7 +886,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver {
|
||||
kr_cutSeletedTag.value = bestNode;
|
||||
kr_currentNodeName.value =
|
||||
kr_truncateText("${bestNode}(auto)", maxLength: 25);
|
||||
kr_moveToSelectedNode();
|
||||
// kr_moveToSelectedNode();
|
||||
kr_updateConnectionInfo();
|
||||
}
|
||||
}
|
||||
@ -1149,7 +1146,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver {
|
||||
}
|
||||
|
||||
// 移动到选中的节点
|
||||
kr_moveToSelectedNode();
|
||||
// kr_moveToSelectedNode();
|
||||
} catch (e) {
|
||||
KRLogUtil.kr_e('选择节点失败: $e', tag: 'HomeController');
|
||||
// 🔧 修复:选择节点失败时,根据连接状态设置合适的延迟值
|
||||
|
||||
@ -22,7 +22,8 @@ class HIAnimatedConnectButton extends GetView<KRHomeController> {
|
||||
return Obx(() {
|
||||
final isConnected = controller.kr_isConnected.value;
|
||||
final delay = controller.kr_currentNodeLatency.value;
|
||||
final isShow = delay == -1 || isConnected;
|
||||
print('当前连接情况$delay----$isConnected');
|
||||
final isShow = isConnected; // delay == -1 || isConnected;
|
||||
|
||||
final Color buttonColor = Theme.of(context).primaryColor;
|
||||
final double screenWidth = Get.width;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user