feat: 修改测试节点问题
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:
2025-10-31 19:05:29 -07:00
parent 445b1e0352
commit b79ce2d15a
5 changed files with 95 additions and 74 deletions
@@ -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',