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 (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 / 创建 Release (push) Has been cancelled
Build Windows / build (push) Has been cancelled

This commit is contained in:
2025-10-30 04:47:53 -07:00
parent 145832093e
commit f42a481452
134 changed files with 8032 additions and 4270 deletions
@@ -0,0 +1,144 @@
import 'package:get/get.dart';
import 'package:kaer_with_panels/app/utils/kr_log_util.dart';
import 'package:kaer_with_panels/app/services/kr_subscribe_service.dart';
import 'package:kaer_with_panels/app/services/singbox_imp/kr_sing_box_imp.dart';
import '../../../localization/app_translations.dart';
import 'package:kaer_with_panels/app/modules/kr_home/controllers/kr_home_controller.dart';
class HINodeListController extends GetxController {
/// 订阅服务
final KRSubscribeService kr_subscribeService = KRSubscribeService();
/// 首页服务
final KRHomeController homeController = Get.find<KRHomeController>();
/// 获取连接类型字符串
String kr_getConnectionTypeString() {
final connectionType = KRSingBoxImp.instance.kr_connectionType.value;
switch (connectionType) {
case KRConnectionType.global:
return AppTranslations.kr_setting.connectionTypeGlobal;
case KRConnectionType.rule:
return AppTranslations.kr_setting.connectionTypeRule;
}
}
/// 更新连接类型
void kr_updateConnectionType(KRConnectionType type) {
KRSingBoxImp.instance.kr_updateConnectionType(type);
KRLogUtil.kr_i('连接类型已更新为: $type', tag: 'HINodeListController');
// 如果当前有选择的国家,触发重选检查
if (homeController.currentSelectedCountry.isNotEmpty) {
KRLogUtil.kr_i('连接类型更新后,检查是否需要重选节点', tag: 'HINodeListController');
// 延迟一下让连接类型更新完成
Future.delayed(const Duration(milliseconds: 500), () {
homeController.checkCountryReselection(KRSingBoxImp.instance.kr_activeGroups);
});
}
}
/// 根据国家选择最快的节点
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;
if (country.isEmpty) {
return [];
}
final countryGroup = kr_subscribeService.countryOutboundList
.firstWhereOrNull((group) => group.country == country);
if (countryGroup == null) {
return [];
}
return countryGroup.outboundList
.where((node) => node.urlTestDelay.value < 65535 && node.urlTestDelay.value > 0)
.map((node) => node.tag)
.toList();
}
/// 手动触发当前国家内的重选
void manualReselection() {
final country = homeController.currentSelectedCountry.value;
if (country.isEmpty) {
KRLogUtil.kr_w('没有选择国家,无法进行重选', tag: 'HINodeListController');
return;
}
KRLogUtil.kr_i('用户手动触发国家内重选', tag: 'HINodeListController');
homeController.performCountryReselection(country);
}
/// 获取当前国家内节点的延迟统计(委托给homeController
Map<String, dynamic> getCurrentCountryLatencyStats() {
return homeController.getCurrentCountryNodeStats();
}
/// 启用/禁用动态重选功能(委托给homeController
void setDynamicReselectionEnabled(bool enabled) {
homeController.setCountryReselectionEnabled(enabled);
}
/// 获取动态重选状态信息
Map<String, dynamic> getDynamicReselectionStatus() {
return {
'enabled': homeController.isCountryReselectionEnabled.value,
'currentCountry': homeController.currentSelectedCountry.value,
'latencyThreshold': homeController.countryReselectionLatencyThreshold,
};
}
}