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

This commit is contained in:
speakeloudest 2025-10-31 19:05:29 -07:00
parent 445b1e0352
commit b79ce2d15a
5 changed files with 95 additions and 74 deletions

View File

@ -27,7 +27,10 @@ class KROutboundItem {
/// URL
String url = "";
@override
String toString() {
return 'KROutboundItem(tag: $tag, country: $country, delay: ${urlTestDelay.value}ms)';
}
///
/// KrNodeListItem KROutboundItem

View File

@ -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;

View File

@ -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',

View File

@ -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');
// 🔧

View File

@ -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;