feat: 完成国家配置
Some checks failed
Build Windows / 编译 libcore (Windows) (20.15.1) (push) Successful in 20m34s
Build Windows / build (push) Has been cancelled

This commit is contained in:
speakeloudest 2025-11-19 01:06:48 -08:00
parent 679c303457
commit 325a63d35f
3 changed files with 28 additions and 6 deletions

View File

@ -132,6 +132,7 @@ class KrOutboundsList {
'url': 'https://www.google.com/generate_204', 'url': 'https://www.google.com/generate_204',
'interval': '10m', 'interval': '10m',
'tolerance': 50, 'tolerance': 50,
"interrupt_exist_connections": true,
}; };
// //
@ -140,7 +141,7 @@ class KrOutboundsList {
// //
allList.add(virtualNode); allList.add(virtualNode);
keyList[autoTag] = virtualNode; keyList[autoTag] = virtualNode;
configJsonList.add(urltestConfig); // configJsonList.add(urltestConfig);
if (kDebugMode) { if (kDebugMode) {
print('✅ 生成虚拟节点: $autoTag, 配置: ${urltestConfig.toString()}'); print('✅ 生成虚拟节点: $autoTag, 配置: ${urltestConfig.toString()}');

View File

@ -309,6 +309,7 @@ class KRSubscribeService {
// //
KRSingBoxImp.instance.kr_saveOutbounds(listModel.configJsonList); KRSingBoxImp.instance.kr_saveOutbounds(listModel.configJsonList);
KRSingBoxImp.instance.kr_saveAllOutbounds(listModel.configJsonList);
// //
_kr_updateSubscribeStatus(); _kr_updateSubscribeStatus();
@ -661,6 +662,8 @@ class KRSubscribeService {
// //
KRSingBoxImp.instance.kr_saveOutbounds(listModel.configJsonList); KRSingBoxImp.instance.kr_saveOutbounds(listModel.configJsonList);
KRSingBoxImp.instance.kr_saveAllOutbounds(listModel.configJsonList);
// //
_kr_updateSubscribeStatus(); _kr_updateSubscribeStatus();
@ -722,6 +725,8 @@ class KRSubscribeService {
// //
KRSingBoxImp.instance.kr_saveOutbounds([]); KRSingBoxImp.instance.kr_saveOutbounds([]);
KRSingBoxImp.instance.kr_saveAllOutbounds([]);
} }
/// ///

View File

@ -65,6 +65,7 @@ class KRSingBoxImp {
Map<String, dynamic> kr_configOption = {}; Map<String, dynamic> kr_configOption = {};
List<Map<String, dynamic>> kr_outbounds = []; List<Map<String, dynamic>> kr_outbounds = [];
List<Map<String, dynamic>> Kr_allOutbounds = [];
/// ///
RxBool kr_isFristStart = false.obs; RxBool kr_isFristStart = false.obs;
@ -1057,7 +1058,7 @@ class KRSingBoxImp {
await Future.delayed(const Duration(milliseconds: 2000)); await Future.delayed(const Duration(milliseconds: 2000));
final savedNode = await KRSecureStorage().kr_readData(key: _keySelectedNode); final savedNode = await KRSecureStorage().kr_readData(key: _keySelectedNode);
if (savedNode != null && savedNode.isNotEmpty && savedNode != 'auto') { if (savedNode != null && savedNode.isNotEmpty && savedNode != 'auto' && !savedNode.endsWith('-auto')) {
KRLogUtil.kr_i('🔄 恢复用户选择的节点: $savedNode', tag: 'SingBox'); KRLogUtil.kr_i('🔄 恢复用户选择的节点: $savedNode', tag: 'SingBox');
try { try {
@ -1098,7 +1099,9 @@ class KRSingBoxImp {
// print("错误堆栈: $stack"); // print("错误堆栈: $stack");
// } // }
// } // }
void kr_saveAllOutbounds(List<Map<String, dynamic>> outbounds) {
Kr_allOutbounds = outbounds;
}
/// ///
void kr_saveOutbounds(List<Map<String, dynamic>> outbounds) async { void kr_saveOutbounds(List<Map<String, dynamic>> outbounds) async {
KRLogUtil.kr_i('💾 开始保存配置文件...', tag: 'SingBox'); KRLogUtil.kr_i('💾 开始保存配置文件...', tag: 'SingBox');
@ -1366,8 +1369,21 @@ class KRSingBoxImp {
// 🔧 // 🔧
if (kr_outbounds.isNotEmpty) { if (kr_outbounds.isNotEmpty) {
KRLogUtil.kr_i('🔄 启动前强制重新生成配置文件...', tag: 'SingBox'); KRLogUtil.kr_i('🔄 启动前强制重新生成配置文件...', tag: 'SingBox');
kr_saveOutbounds(kr_outbounds); final selectedNode = await KRSecureStorage().kr_readData(key: _keySelectedNode);
// var toSave = Kr_allOutbounds;
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');
}
kr_saveOutbounds(toSave);
await Future.delayed(const Duration(milliseconds: 100)); await Future.delayed(const Duration(milliseconds: 100));
} }
@ -1814,7 +1830,7 @@ class KRSingBoxImp {
// 🔄 auto // 🔄 auto
// urltest // urltest
_nodeSelectionTimer?.cancel(); _nodeSelectionTimer?.cancel();
if (tag != 'auto') { if (tag != 'auto' && !tag.endsWith('-auto')) {
KRLogUtil.kr_i('🔁 启动节点选择监控,防止被 auto 覆盖', tag: 'SingBox'); KRLogUtil.kr_i('🔁 启动节点选择监控,防止被 auto 覆盖', tag: 'SingBox');
_nodeSelectionTimer = Timer.periodic(const Duration(seconds: 20), (timer) { _nodeSelectionTimer = Timer.periodic(const Duration(seconds: 20), (timer) {
// 20 // 20