Adds Xray and Singbox support config type (#7789)

* Adds Xray and Singbox config type support

* Unify multiline logical expression formatting
pull/7797/head
DHR60 2025-08-18 17:28:49 +08:00 committed by GitHub
parent 7b7fe0ef46
commit 89893c0945
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 49 additions and 44 deletions

View File

@ -289,6 +289,31 @@ public class Global
"sing_box" "sing_box"
]; ];
public static readonly HashSet<EConfigType> XraySupportConfigType =
[
EConfigType.VMess,
EConfigType.VLESS,
EConfigType.Shadowsocks,
EConfigType.Trojan,
EConfigType.WireGuard,
EConfigType.SOCKS,
EConfigType.HTTP,
];
public static readonly HashSet<EConfigType> SingboxSupportConfigType =
[
EConfigType.VMess,
EConfigType.VLESS,
EConfigType.Shadowsocks,
EConfigType.Trojan,
EConfigType.Hysteria2,
EConfigType.TUIC,
EConfigType.Anytls,
EConfigType.WireGuard,
EConfigType.SOCKS,
EConfigType.HTTP,
];
public static readonly List<string> DomainStrategies = public static readonly List<string> DomainStrategies =
[ [
AsIs, AsIs,

View File

@ -133,7 +133,7 @@ public partial class CoreConfigSingboxService(Config config)
foreach (var it in selecteds) foreach (var it in selecteds)
{ {
if (it.ConfigType == EConfigType.Custom) if (!Global.SingboxSupportConfigType.Contains(it.ConfigType))
{ {
continue; continue;
} }
@ -381,7 +381,7 @@ public partial class CoreConfigSingboxService(Config config)
var proxyProfiles = new List<ProfileItem>(); var proxyProfiles = new List<ProfileItem>();
foreach (var it in selecteds) foreach (var it in selecteds)
{ {
if (it.ConfigType == EConfigType.Custom) if (!Global.SingboxSupportConfigType.Contains(it.ConfigType))
{ {
continue; continue;
} }

View File

@ -372,7 +372,7 @@ public partial class CoreConfigSingboxService
var prevNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.PrevProfile); var prevNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.PrevProfile);
string? prevOutboundTag = null; string? prevOutboundTag = null;
if (prevNode is not null if (prevNode is not null
&& prevNode.ConfigType != EConfigType.Custom) && Global.SingboxSupportConfigType.Contains(prevNode.ConfigType))
{ {
prevOutboundTag = $"prev-{Global.ProxyTag}"; prevOutboundTag = $"prev-{Global.ProxyTag}";
var prevServer = await GenServer(prevNode); var prevServer = await GenServer(prevNode);
@ -463,7 +463,7 @@ public partial class CoreConfigSingboxService
{ {
var prevNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.PrevProfile); var prevNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.PrevProfile);
if (prevNode is not null if (prevNode is not null
&& prevNode.ConfigType != EConfigType.Custom) && Global.SingboxSupportConfigType.Contains(prevNode.ConfigType))
{ {
var prevOutbound = JsonUtils.Deserialize<Outbound4Sbox>(txtOutbound); var prevOutbound = JsonUtils.Deserialize<Outbound4Sbox>(txtOutbound);
await GenOutbound(prevNode, prevOutbound); await GenOutbound(prevNode, prevOutbound);
@ -558,7 +558,7 @@ public partial class CoreConfigSingboxService
// Next proxy // Next proxy
var nextNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.NextProfile); var nextNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.NextProfile);
if (nextNode is not null if (nextNode is not null
&& nextNode.ConfigType != EConfigType.Custom) && Global.SingboxSupportConfigType.Contains(nextNode.ConfigType))
{ {
nextOutbound ??= await GenServer(nextNode); nextOutbound ??= await GenServer(nextNode);
nextOutbound.tag = outbound.tag; nextOutbound.tag = outbound.tag;

View File

@ -338,7 +338,7 @@ public partial class CoreConfigSingboxService
var node = await AppManager.Instance.GetProfileItemViaRemarks(outboundTag); var node = await AppManager.Instance.GetProfileItemViaRemarks(outboundTag);
if (node == null if (node == null
|| node.ConfigType == EConfigType.Custom) || !Global.SingboxSupportConfigType.Contains(node.ConfigType))
{ {
return Global.ProxyTag; return Global.ProxyTag;
} }

View File

@ -110,11 +110,7 @@ public partial class CoreConfigV2rayService(Config config)
var proxyProfiles = new List<ProfileItem>(); var proxyProfiles = new List<ProfileItem>();
foreach (var it in selecteds) foreach (var it in selecteds)
{ {
if (it.ConfigType == EConfigType.Custom) if (!Global.XraySupportConfigType.Contains(it.ConfigType))
{
continue;
}
if (it.ConfigType is EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.Anytls)
{ {
continue; continue;
} }
@ -250,7 +246,7 @@ public partial class CoreConfigV2rayService(Config config)
foreach (var it in selecteds) foreach (var it in selecteds)
{ {
if (it.ConfigType == EConfigType.Custom) if (!Global.XraySupportConfigType.Contains(it.ConfigType))
{ {
continue; continue;
} }

View File

@ -187,9 +187,9 @@ public partial class CoreConfigV2rayService
foreach (var profile in new[] { subItem.PrevProfile, subItem.NextProfile }) foreach (var profile in new[] { subItem.PrevProfile, subItem.NextProfile })
{ {
var profileNode = await AppManager.Instance.GetProfileItemViaRemarks(profile); var profileNode = await AppManager.Instance.GetProfileItemViaRemarks(profile);
if (profileNode is not null && if (profileNode is not null
profileNode.ConfigType is not (EConfigType.Custom or EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.Anytls) && && Global.XraySupportConfigType.Contains(profileNode.ConfigType)
Utils.IsDomain(profileNode.Address)) && Utils.IsDomain(profileNode.Address))
{ {
directDomainList.Add(profileNode.Address); directDomainList.Add(profileNode.Address);
} }
@ -217,11 +217,11 @@ public partial class CoreConfigV2rayService
AddDnsServers(directDNSAddress, directGeositeList); AddDnsServers(directDNSAddress, directGeositeList);
AddDnsServers(directDNSAddress, expectedDomainList, expectedIPs); AddDnsServers(directDNSAddress, expectedDomainList, expectedIPs);
var useDirectDns = rules?.LastOrDefault() is { } lastRule && var useDirectDns = rules?.LastOrDefault() is { } lastRule
lastRule.OutboundTag == Global.DirectTag && && lastRule.OutboundTag == Global.DirectTag
(lastRule.Port == "0-65535" || && (lastRule.Port == "0-65535"
lastRule.Network == "tcp,udp" || || lastRule.Network == "tcp,udp"
lastRule.Ip?.Contains("0.0.0.0/0") == true); || lastRule.Ip?.Contains("0.0.0.0/0") == true);
var defaultDnsServers = useDirectDns ? directDNSAddress : remoteDNSAddress; var defaultDnsServers = useDirectDns ? directDNSAddress : remoteDNSAddress;
v2rayConfig.dns.servers.AddRange(defaultDnsServers); v2rayConfig.dns.servers.AddRange(defaultDnsServers);
@ -391,9 +391,7 @@ public partial class CoreConfigV2rayService
// Previous proxy // Previous proxy
var prevNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.PrevProfile); var prevNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.PrevProfile);
if (prevNode is not null if (prevNode is not null
&& prevNode.ConfigType != EConfigType.Custom && Global.SingboxSupportConfigType.Contains(prevNode.ConfigType)
&& prevNode.ConfigType != EConfigType.Hysteria2
&& prevNode.ConfigType != EConfigType.TUIC
&& Utils.IsDomain(prevNode.Address)) && Utils.IsDomain(prevNode.Address))
{ {
domainList.Add(prevNode.Address); domainList.Add(prevNode.Address);
@ -402,9 +400,7 @@ public partial class CoreConfigV2rayService
// Next proxy // Next proxy
var nextNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.NextProfile); var nextNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.NextProfile);
if (nextNode is not null if (nextNode is not null
&& nextNode.ConfigType != EConfigType.Custom && Global.SingboxSupportConfigType.Contains(nextNode.ConfigType)
&& nextNode.ConfigType != EConfigType.Hysteria2
&& nextNode.ConfigType != EConfigType.TUIC
&& Utils.IsDomain(nextNode.Address)) && Utils.IsDomain(nextNode.Address))
{ {
domainList.Add(nextNode.Address); domainList.Add(nextNode.Address);

View File

@ -529,10 +529,7 @@ public partial class CoreConfigV2rayService
var prevNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.PrevProfile); var prevNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.PrevProfile);
string? prevOutboundTag = null; string? prevOutboundTag = null;
if (prevNode is not null if (prevNode is not null
&& prevNode.ConfigType != EConfigType.Custom && Global.XraySupportConfigType.Contains(prevNode.ConfigType))
&& prevNode.ConfigType != EConfigType.Hysteria2
&& prevNode.ConfigType != EConfigType.TUIC
&& prevNode.ConfigType != EConfigType.Anytls)
{ {
var prevOutbound = JsonUtils.Deserialize<Outbounds4Ray>(txtOutbound); var prevOutbound = JsonUtils.Deserialize<Outbounds4Ray>(txtOutbound);
await GenOutbound(prevNode, prevOutbound); await GenOutbound(prevNode, prevOutbound);
@ -605,10 +602,7 @@ public partial class CoreConfigV2rayService
{ {
var prevNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.PrevProfile); var prevNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.PrevProfile);
if (prevNode is not null if (prevNode is not null
&& prevNode.ConfigType != EConfigType.Custom && Global.XraySupportConfigType.Contains(prevNode.ConfigType))
&& prevNode.ConfigType != EConfigType.Hysteria2
&& prevNode.ConfigType != EConfigType.TUIC
&& prevNode.ConfigType != EConfigType.Anytls)
{ {
var prevOutbound = JsonUtils.Deserialize<Outbounds4Ray>(txtOutbound); var prevOutbound = JsonUtils.Deserialize<Outbounds4Ray>(txtOutbound);
await GenOutbound(prevNode, prevOutbound); await GenOutbound(prevNode, prevOutbound);
@ -675,10 +669,7 @@ public partial class CoreConfigV2rayService
// Next proxy // Next proxy
var nextNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.NextProfile); var nextNode = await AppManager.Instance.GetProfileItemViaRemarks(subItem.NextProfile);
if (nextNode is not null if (nextNode is not null
&& nextNode.ConfigType != EConfigType.Custom && Global.XraySupportConfigType.Contains(nextNode.ConfigType))
&& nextNode.ConfigType != EConfigType.Hysteria2
&& nextNode.ConfigType != EConfigType.TUIC
&& nextNode.ConfigType != EConfigType.Anytls)
{ {
if (nextOutbound == null) if (nextOutbound == null)
{ {

View File

@ -126,10 +126,7 @@ public partial class CoreConfigV2rayService
var node = await AppManager.Instance.GetProfileItemViaRemarks(outboundTag); var node = await AppManager.Instance.GetProfileItemViaRemarks(outboundTag);
if (node == null if (node == null
|| node.ConfigType == EConfigType.Custom || !Global.XraySupportConfigType.Contains(node.ConfigType))
|| node.ConfigType == EConfigType.Hysteria2
|| node.ConfigType == EConfigType.TUIC
|| node.ConfigType == EConfigType.Anytls)
{ {
return Global.ProxyTag; return Global.ProxyTag;
} }

View File

@ -356,8 +356,8 @@ public class SpeedtestService
private List<List<ServerTestItem>> GetTestBatchItem(List<ServerTestItem> lstSelected, int pageSize) private List<List<ServerTestItem>> GetTestBatchItem(List<ServerTestItem> lstSelected, int pageSize)
{ {
List<List<ServerTestItem>> lstTest = new(); List<List<ServerTestItem>> lstTest = new();
var lst1 = lstSelected.Where(t => t.ConfigType is not (EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.Anytls)).ToList(); var lst1 = lstSelected.Where(t => Global.XraySupportConfigType.Contains(t.ConfigType)).ToList();
var lst2 = lstSelected.Where(t => t.ConfigType is EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.Anytls).ToList(); var lst2 = lstSelected.Where(t => Global.SingboxSupportConfigType.Contains(t.ConfigType) && !Global.XraySupportConfigType.Contains(t.ConfigType)).ToList();
for (var num = 0; num < (int)Math.Ceiling(lst1.Count * 1.0 / pageSize); num++) for (var num = 0; num < (int)Math.Ceiling(lst1.Count * 1.0 / pageSize); num++)
{ {