feat: 修改国家选择匹配问题
This commit is contained in:
parent
bcb4d17236
commit
3b05d4ff72
@ -59,6 +59,8 @@ class UserInfoCard extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
'ID: $userId',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14.sp,
|
||||
|
||||
@ -309,7 +309,7 @@ class KRSubscribeService {
|
||||
|
||||
// 保存配置
|
||||
KRSingBoxImp.instance.kr_saveOutbounds(listModel.configJsonList);
|
||||
KRSingBoxImp.instance.kr_saveAllOutbounds(listModel.configJsonList);
|
||||
KRSingBoxImp.instance.kr_saveAllOutbounds(listModel.countryOutboundList);
|
||||
|
||||
// 更新试用和订阅状态
|
||||
_kr_updateSubscribeStatus();
|
||||
@ -662,7 +662,7 @@ class KRSubscribeService {
|
||||
|
||||
// 保存配置
|
||||
KRSingBoxImp.instance.kr_saveOutbounds(listModel.configJsonList);
|
||||
KRSingBoxImp.instance.kr_saveAllOutbounds(listModel.configJsonList);
|
||||
KRSingBoxImp.instance.kr_saveAllOutbounds(listModel.countryOutboundList);
|
||||
|
||||
// 更新试用和订阅状态
|
||||
_kr_updateSubscribeStatus();
|
||||
|
||||
@ -19,6 +19,8 @@ import '../../../singbox/model/singbox_config_option.dart';
|
||||
import '../../../singbox/model/singbox_outbound.dart';
|
||||
import '../../../singbox/model/singbox_stats.dart';
|
||||
import '../../../singbox/model/singbox_status.dart';
|
||||
import '../../model/business/kr_group_outbound_list.dart';
|
||||
import '../../model/business/kr_outbound_item.dart';
|
||||
import '../../utils/kr_country_util.dart';
|
||||
import '../../utils/kr_log_util.dart';
|
||||
import '../../utils/kr_secure_storage.dart';
|
||||
@ -66,7 +68,7 @@ class KRSingBoxImp {
|
||||
Map<String, dynamic> kr_configOption = {};
|
||||
|
||||
List<Map<String, dynamic>> kr_outbounds = [];
|
||||
List<Map<String, dynamic>> Kr_allOutbounds = [];
|
||||
List<KRCountryOutboundList> Kr_allOutbounds = [];
|
||||
|
||||
/// 首次启动
|
||||
RxBool kr_isFristStart = false.obs;
|
||||
@ -1202,8 +1204,13 @@ class KRSingBoxImp {
|
||||
// print("错误堆栈: $stack");
|
||||
// }
|
||||
// }
|
||||
void kr_saveAllOutbounds(List<Map<String, dynamic>> outbounds) {
|
||||
void kr_saveAllOutbounds(List<KRCountryOutboundList> outbounds) {
|
||||
Kr_allOutbounds = outbounds;
|
||||
KRLogUtil.kr_i('📊 保存国家分组: ${Kr_allOutbounds.length}', tag: 'SingBox');
|
||||
for (int i = 0; i < Kr_allOutbounds.length; i++) {
|
||||
final c = Kr_allOutbounds[i];
|
||||
KRLogUtil.kr_i(' group[$i] country="${c.country}" outbounds=${c.outboundList.length}', tag: 'SingBox');
|
||||
}
|
||||
}
|
||||
/// 保存配置文件
|
||||
void kr_saveOutbounds(List<Map<String, dynamic>> outbounds) async {
|
||||
@ -1457,18 +1464,40 @@ class KRSingBoxImp {
|
||||
if (kr_outbounds.isNotEmpty) {
|
||||
KRLogUtil.kr_i('🔄 启动前强制重新生成配置文件...', tag: 'SingBox');
|
||||
final selectedNode = await KRSecureStorage().kr_readData(key: _keySelectedNode);
|
||||
var toSave = Kr_allOutbounds;
|
||||
KRLogUtil.kr_i('📊 国家分组数量: ${Kr_allOutbounds.length}', tag: 'SingBox');
|
||||
for (int i = 0; i < Kr_allOutbounds.length; i++) {
|
||||
final g = Kr_allOutbounds[i];
|
||||
KRLogUtil.kr_i('Kr_allOutbounds[$i] country="${g.country}" outbounds=${g.outboundList.length}', tag: 'SingBox');
|
||||
}
|
||||
List<Map<String, dynamic>> toSave = [];
|
||||
if (selectedNode != null && selectedNode.endsWith('-auto')) {
|
||||
KRLogUtil.kr_i('🤖 检测到自动国家节点: $selectedNode', tag: 'SingBox');
|
||||
final selectedCountry = selectedNode.replaceAll(RegExp(r'-auto$'), '');
|
||||
toSave = Kr_allOutbounds.where((o) {
|
||||
final country = o['country']?.toString() ?? '';
|
||||
if (country.isNotEmpty) return country == selectedCountry;
|
||||
final tag = o['tag']?.toString() ?? '';
|
||||
if (tag == selectedNode) return true;
|
||||
return tag.toLowerCase().contains(selectedCountry.toLowerCase());
|
||||
}).toList();
|
||||
KRLogUtil.kr_i('✅ 自动国家过滤: ${toSave.length}/${Kr_allOutbounds.length}', tag: 'SingBox');
|
||||
String selectedCountry = selectedNode.replaceAll(RegExp(r'-auto$'), '');
|
||||
final selectedCountryLower = selectedCountry.toLowerCase();
|
||||
final matchedGroup = Kr_allOutbounds.firstWhere(
|
||||
(g) => g.country.toLowerCase() == selectedCountryLower,
|
||||
orElse: () => KRCountryOutboundList(country: '', outboundList: []),
|
||||
);
|
||||
if (matchedGroup.country.isNotEmpty) {
|
||||
KRLogUtil.kr_i('🎯 命中分组: ${matchedGroup.country}, 节点数: ${matchedGroup.outboundList.length}', tag: 'SingBox');
|
||||
toSave = matchedGroup.outboundList.map((it) => it.config).toList();
|
||||
} else {
|
||||
for (final g in Kr_allOutbounds) {
|
||||
for (final it in g.outboundList) {
|
||||
final tagLower = it.tag.toLowerCase();
|
||||
if (tagLower == selectedNode.toLowerCase() || tagLower.contains(selectedCountryLower)) {
|
||||
toSave.add(it.config);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
KRLogUtil.kr_i('✅ 自动国家过滤: ${toSave.length}', tag: 'SingBox');
|
||||
} else {
|
||||
for (final g in Kr_allOutbounds) {
|
||||
for (final it in g.outboundList) {
|
||||
toSave.add(it.config);
|
||||
}
|
||||
}
|
||||
}
|
||||
kr_saveOutbounds(toSave);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user