From 29a5abf4d6a762a3e6edf452436be6ffa5a65b5c Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 10 Sep 2025 19:43:11 +0800 Subject: [PATCH 01/12] Optimization and improvement --- v2rayN/ServiceLib/Models/CheckUpdateModel.cs | 7 +++++-- v2rayN/ServiceLib/Models/ClashProxyModel.cs | 9 ++++++--- v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs | 5 +---- .../ServiceLib/ViewModels/ClashProxiesViewModel.cs | 2 -- v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs | 12 ------------ 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/v2rayN/ServiceLib/Models/CheckUpdateModel.cs b/v2rayN/ServiceLib/Models/CheckUpdateModel.cs index 85225bc1..f06eedc9 100644 --- a/v2rayN/ServiceLib/Models/CheckUpdateModel.cs +++ b/v2rayN/ServiceLib/Models/CheckUpdateModel.cs @@ -1,10 +1,13 @@ +using ReactiveUI; +using ReactiveUI.Fody.Helpers; + namespace ServiceLib.Models; -public class CheckUpdateModel +public class CheckUpdateModel : ReactiveObject { public bool? IsSelected { get; set; } public string? CoreType { get; set; } - public string? Remarks { get; set; } + [Reactive] public string? Remarks { get; set; } public string? FileName { get; set; } public bool? IsFinished { get; set; } } diff --git a/v2rayN/ServiceLib/Models/ClashProxyModel.cs b/v2rayN/ServiceLib/Models/ClashProxyModel.cs index fd534309..014b0f12 100644 --- a/v2rayN/ServiceLib/Models/ClashProxyModel.cs +++ b/v2rayN/ServiceLib/Models/ClashProxyModel.cs @@ -1,7 +1,10 @@ +using ReactiveUI; +using ReactiveUI.Fody.Helpers; + namespace ServiceLib.Models; [Serializable] -public class ClashProxyModel +public class ClashProxyModel : ReactiveObject { public string? Name { get; set; } @@ -9,9 +12,9 @@ public class ClashProxyModel public string? Now { get; set; } - public int Delay { get; set; } + [Reactive] public int Delay { get; set; } - public string? DelayName { get; set; } + [Reactive] public string? DelayName { get; set; } public bool IsActive { get; set; } } diff --git a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs index 23839141..9dd43a75 100644 --- a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs @@ -334,9 +334,6 @@ public class CheckUpdateViewModel : MyReactiveObject { return; } - - var itemCopy = JsonUtils.DeepCopy(found); - itemCopy.Remarks = model.Remarks; - CheckUpdateModels.Replace(found, itemCopy); + found.Remarks = model.Remarks; } } diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index 54cbdc8d..343d49df 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -391,7 +391,6 @@ public class ClashProxiesViewModel : MyReactiveObject public async Task ProxiesDelayTestResult(SpeedTestResult result) { - //UpdateHandler(false, $"{item.name}={result}"); var detail = ProxyDetails.FirstOrDefault(it => it.Name == result.IndexId); if (detail == null) { @@ -414,7 +413,6 @@ public class ClashProxiesViewModel : MyReactiveObject detail.Delay = _delayTimeout; detail.DelayName = string.Empty; } - ProxyDetails.Replace(detail, JsonUtils.DeepCopy(detail)); } #endregion proxy function diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index 14216fee..4c0fd2b9 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -293,7 +293,6 @@ public class ProfilesViewModel : MyReactiveObject { item.SpeedVal = result.Speed ?? string.Empty; } - //_profileItems.Replace(item, JsonUtils.DeepCopy(item)); } public async Task UpdateStatistics(ServerSpeedItem update) @@ -314,17 +313,6 @@ public class ProfilesViewModel : MyReactiveObject item.TodayUp = Utils.HumanFy(update.TodayUp); item.TotalDown = Utils.HumanFy(update.TotalDown); item.TotalUp = Utils.HumanFy(update.TotalUp); - - //if (SelectedProfile?.IndexId == item.IndexId) - //{ - // var temp = JsonUtils.DeepCopy(item); - // _profileItems.Replace(item, temp); - // SelectedProfile = temp; - //} - //else - //{ - // _profileItems.Replace(item, JsonUtils.DeepCopy(item)); - //} } } catch From 3e0578f775e5c30e255243b711136574ea67d33e Mon Sep 17 00:00:00 2001 From: JieXu Date: Fri, 12 Sep 2025 16:24:59 +0800 Subject: [PATCH 02/12] Update CheckUpdateViewModel.cs (#7932) * Update CheckUpdateViewModel.cs * Update Utils.cs * Update Utils.cs * Update Utils.cs * Update CheckUpdateViewModel.cs * Update CheckUpdateViewModel.cs * Update Utils.cs --- v2rayN/ServiceLib/Common/Utils.cs | 49 +++++++++++++++++++ .../ViewModels/CheckUpdateViewModel.cs | 15 ++++++ 2 files changed, 64 insertions(+) diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index 49a359c0..bfc74801 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -857,6 +857,55 @@ public class Utils return false; } + public static bool IsPackagedInstall() + { + try + { + if (IsWindows() || IsOSX()) + { + return false; + } + + if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPIMAGE"))) + { + return true; + } + + var exePath = GetExePath(); + var baseDir = string.IsNullOrEmpty(exePath) ? StartupPath() : Path.GetDirectoryName(exePath) ?? ""; + var p = baseDir.Replace('\\', '/'); + + if (string.IsNullOrEmpty(p)) + { + return false; + } + + if (p.Contains("/.mount_", StringComparison.Ordinal)) + { + return true; + } + + if (p.StartsWith("/opt/v2rayN", StringComparison.OrdinalIgnoreCase)) + { + return true; + } + + if (p.StartsWith("/usr/lib/v2rayN", StringComparison.OrdinalIgnoreCase)) + { + return true; + } + + if (p.StartsWith("/usr/share/v2rayN", StringComparison.OrdinalIgnoreCase)) + { + return true; + } + } + catch + { + } + return false; + } + private static async Task GetLinuxUserId() { var arg = new List() { "-c", "id -u" }; diff --git a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs index 9dd43a75..4c9c0550 100644 --- a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs @@ -63,6 +63,16 @@ public class CheckUpdateViewModel : MyReactiveObject private CheckUpdateModel GetCheckUpdateModel(string coreType) { + if (coreType == _v2rayN && Utils.IsPackagedInstall()) + { + return new() + { + IsSelected = false, + CoreType = coreType, + Remarks = ResUI.menuCheckUpdate + " (Not Support)", + }; + } + return new() { IsSelected = _config.CheckUpdateItem.SelectedCoreTypes?.Contains(coreType) ?? true, @@ -104,6 +114,11 @@ public class CheckUpdateViewModel : MyReactiveObject } else if (item.CoreType == _v2rayN) { + if (Utils.IsPackagedInstall()) + { + await UpdateView(_v2rayN, "Not Support"); + continue; + } await CheckUpdateN(EnableCheckPreReleaseUpdate); } else if (item.CoreType == ECoreType.Xray.ToString()) From 54e83391d0af9d9e55a1971f0ae728d100936479 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Fri, 12 Sep 2025 16:28:31 +0800 Subject: [PATCH 03/12] Pre-resolve to apply hosts (#7937) --- v2rayN/ServiceLib/Common/Utils.cs | 26 +++++++++++++++++++ .../CoreConfig/Singbox/SingboxDnsService.cs | 12 +-------- .../Singbox/SingboxRoutingService.cs | 25 ++++++++++++++++++ .../CoreConfig/V2ray/V2rayDnsService.cs | 12 +-------- 4 files changed, 53 insertions(+), 22 deletions(-) diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index bfc74801..358d4e9a 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -331,6 +331,32 @@ public class Utils .ToList(); } + public static Dictionary> ParseHostsToDictionary(string hostsContent) + { + var userHostsMap = hostsContent + .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) + .Select(line => line.Trim()) + // skip full-line comments + .Where(line => !string.IsNullOrWhiteSpace(line) && !line.StartsWith("#")) + // strip inline comments (truncate at '#') + .Select(line => + { + var index = line.IndexOf('#'); + return index >= 0 ? line.Substring(0, index).Trim() : line; + }) + // ensure line still contains valid parts + .Where(line => !string.IsNullOrWhiteSpace(line) && line.Contains(' ')) + .Select(line => line.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)) + .Where(parts => parts.Length >= 2) + .GroupBy(parts => parts[0]) + .ToDictionary( + group => group.Key, + group => group.SelectMany(parts => parts.Skip(1)).ToList() + ); + + return userHostsMap; + } + #endregion 转换函数 #region 数据检查 diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs index 2f0f8015..306572a1 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs @@ -94,17 +94,7 @@ public partial class CoreConfigSingboxService if (!simpleDNSItem.Hosts.IsNullOrEmpty()) { - var userHostsMap = simpleDNSItem.Hosts - .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) - .Select(line => line.Trim()) - .Where(line => !string.IsNullOrWhiteSpace(line) && line.Contains(' ')) - .Select(line => line.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)) - .Where(parts => parts.Length >= 2) - .GroupBy(parts => parts[0]) - .ToDictionary( - group => group.Key, - group => group.SelectMany(parts => parts.Skip(1)).ToList() - ); + var userHostsMap = Utils.ParseHostsToDictionary(simpleDNSItem.Hosts); foreach (var kvp in userHostsMap) { diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs index 24804c50..0b364785 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs @@ -71,6 +71,31 @@ public partial class CoreConfigSingboxService }); } + var hostsDomains = new List(); + var systemHostsMap = Utils.GetSystemHosts(); + foreach (var kvp in systemHostsMap) + { + hostsDomains.Add(kvp.Key); + } + var dnsItem = await AppManager.Instance.GetDNSItem(ECoreType.sing_box); + if (dnsItem == null || dnsItem.Enabled == false) + { + var simpleDNSItem = _config.SimpleDNSItem; + if (!simpleDNSItem.Hosts.IsNullOrEmpty()) + { + var userHostsMap = Utils.ParseHostsToDictionary(simpleDNSItem.Hosts); + foreach (var kvp in userHostsMap) + { + hostsDomains.Add(kvp.Key); + } + } + } + singboxConfig.route.rules.Add(new() + { + action = "resolve", + domain = hostsDomains, + }); + singboxConfig.route.rules.Add(new() { outbound = Global.DirectTag, diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs index 6f64e923..744286d4 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs @@ -261,17 +261,7 @@ public partial class CoreConfigV2rayService if (!simpleDNSItem.Hosts.IsNullOrEmpty()) { - var userHostsMap = simpleDNSItem.Hosts - .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) - .Select(line => line.Trim()) - .Where(line => !string.IsNullOrWhiteSpace(line) && line.Contains(' ')) - .Select(line => line.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)) - .Where(parts => parts.Length >= 2) - .GroupBy(parts => parts[0]) - .ToDictionary( - group => group.Key, - group => group.SelectMany(parts => parts.Skip(1)).ToList() - ); + var userHostsMap = Utils.ParseHostsToDictionary(simpleDNSItem.Hosts); foreach (var kvp in userHostsMap) { From 436d95576ec6cb612590524fa3335e2b30966639 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 12 Sep 2025 16:45:55 +0800 Subject: [PATCH 04/12] Optimization and improvement JsonUtils --- v2rayN/ServiceLib/Common/JsonUtils.cs | 40 +++++++++++++++++++-------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/v2rayN/ServiceLib/Common/JsonUtils.cs b/v2rayN/ServiceLib/Common/JsonUtils.cs index 6954e124..4fbaa0e1 100644 --- a/v2rayN/ServiceLib/Common/JsonUtils.cs +++ b/v2rayN/ServiceLib/Common/JsonUtils.cs @@ -9,6 +9,31 @@ public class JsonUtils { private static readonly string _tag = "JsonUtils"; + private static readonly JsonSerializerOptions _defaultDeserializeOptions = new() + { + PropertyNameCaseInsensitive = true, + ReadCommentHandling = JsonCommentHandling.Skip + }; + + private static readonly JsonSerializerOptions _defaultSerializeOptions = new() + { + WriteIndented = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping + }; + + private static readonly JsonSerializerOptions _nullValueSerializeOptions = new() + { + WriteIndented = true, + DefaultIgnoreCondition = JsonIgnoreCondition.Never, + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping + }; + + private static readonly JsonDocumentOptions _defaultDocumentOptions = new() + { + CommentHandling = JsonCommentHandling.Skip + }; + /// /// DeepCopy /// @@ -34,11 +59,7 @@ public class JsonUtils { return default; } - var options = new JsonSerializerOptions - { - PropertyNameCaseInsensitive = true - }; - return JsonSerializer.Deserialize(strJson, options); + return JsonSerializer.Deserialize(strJson, _defaultDeserializeOptions); } catch { @@ -59,7 +80,7 @@ public class JsonUtils { return null; } - return JsonNode.Parse(strJson); + return JsonNode.Parse(strJson, nodeOptions: null, _defaultDocumentOptions); } catch { @@ -84,12 +105,7 @@ public class JsonUtils { return result; } - var options = new JsonSerializerOptions - { - WriteIndented = indented, - DefaultIgnoreCondition = nullValue ? JsonIgnoreCondition.Never : JsonIgnoreCondition.WhenWritingNull, - Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping - }; + var options = nullValue ? _nullValueSerializeOptions : _defaultSerializeOptions; result = JsonSerializer.Serialize(obj, options); } catch (Exception ex) From c559914ff7bc0fbd4eae28da007531f9e3a3953a Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 12 Sep 2025 17:01:53 +0800 Subject: [PATCH 05/12] Fix https://github.com/2dust/v2rayN/issues/7938 --- v2rayN/ServiceLib/Handler/Fmt/ClashFmt.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2rayN/ServiceLib/Handler/Fmt/ClashFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/ClashFmt.cs index f711c51f..6c6f2bbf 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/ClashFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/ClashFmt.cs @@ -4,7 +4,7 @@ public class ClashFmt : BaseFmt { public static ProfileItem? ResolveFull(string strData, string? subRemarks) { - if (Contains(strData, "port", "socks-port", "proxies")) + if (Contains(strData, "external-controller", "-port", "proxies")) { var fileName = WriteAllText(strData, "yaml"); From a87a015c03f86e28c60b4ba008db15de4c708400 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Fri, 12 Sep 2025 20:28:24 +0800 Subject: [PATCH 06/12] Fix some minor UI bugs (#7941) --- v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml | 2 +- v2rayN/v2rayN.Desktop/Views/RoutingRuleSettingWindow.axaml | 1 + v2rayN/v2rayN.Desktop/Views/RoutingSettingWindow.axaml | 1 + v2rayN/v2rayN/Views/AddServerWindow.xaml | 2 +- v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs | 2 ++ 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml index ab6bc223..7aa6a0be 100644 --- a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml @@ -400,7 +400,7 @@ Grid.Column="1" Width="400" Margin="{StaticResource Margin4}" - Watermark="1000:2000,3000:4000" /> + Watermark="1000-2000,3000,4000" /> Date: Sat, 13 Sep 2025 09:41:34 +0800 Subject: [PATCH 07/12] Bug fix https://github.com/2dust/v2rayN/issues/7944 --- .../Services/CoreConfig/Singbox/SingboxRoutingService.cs | 7 +++++++ .../Services/CoreConfig/V2ray/V2rayRoutingService.cs | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs index 0b364785..9fec047c 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs @@ -368,6 +368,13 @@ public partial class CoreConfigSingboxService return Global.ProxyTag; } + var tag = Global.ProxyTag + node.IndexId.ToString(); + if (singboxConfig.outbounds.Any(o => o.tag == tag) + || (singboxConfig.endpoints != null && singboxConfig.endpoints.Any(e => e.tag == tag))) + { + return tag; + } + var server = await GenServer(node); if (server is null) { diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs index 1cb46bf2..d39ea833 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs @@ -131,10 +131,16 @@ public partial class CoreConfigV2rayService return Global.ProxyTag; } + var tag = Global.ProxyTag + node.IndexId.ToString(); + if (v2rayConfig.outbounds.Any(p => p.tag == tag)) + { + return tag; + } + var txtOutbound = EmbedUtils.GetEmbedText(Global.V2raySampleOutbound); var outbound = JsonUtils.Deserialize(txtOutbound); await GenOutbound(node, outbound); - outbound.tag = Global.ProxyTag + node.IndexId.ToString(); + outbound.tag = tag; v2rayConfig.outbounds.Add(outbound); return outbound.tag; From 4606e78570c52ed7dddde315519ee935775afc83 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 13 Sep 2025 09:46:28 +0800 Subject: [PATCH 08/12] Update Directory.Packages.props --- v2rayN/Directory.Packages.props | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/v2rayN/Directory.Packages.props b/v2rayN/Directory.Packages.props index 9193271c..6f8fadf2 100644 --- a/v2rayN/Directory.Packages.props +++ b/v2rayN/Directory.Packages.props @@ -5,10 +5,10 @@ false - - - - + + + + From ec627bdb8252d275a69d4a1e193e892c1d19e075 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 13 Sep 2025 09:53:03 +0800 Subject: [PATCH 09/12] up 7.14.10 --- v2rayN/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2rayN/Directory.Build.props b/v2rayN/Directory.Build.props index 785e23d1..7bae47f6 100644 --- a/v2rayN/Directory.Build.props +++ b/v2rayN/Directory.Build.props @@ -1,7 +1,7 @@ - 7.14.9 + 7.14.10 From cb182125f6d2a7e431de3867a8de1be7dde2cffb Mon Sep 17 00:00:00 2001 From: DHR60 Date: Sat, 13 Sep 2025 11:13:09 +0800 Subject: [PATCH 10/12] Fix (#7946) https://github.com/2dust/v2rayN/pull/7937 --- .../Singbox/SingboxRoutingService.cs | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs index 9fec047c..21dfb101 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs @@ -72,11 +72,6 @@ public partial class CoreConfigSingboxService } var hostsDomains = new List(); - var systemHostsMap = Utils.GetSystemHosts(); - foreach (var kvp in systemHostsMap) - { - hostsDomains.Add(kvp.Key); - } var dnsItem = await AppManager.Instance.GetDNSItem(ECoreType.sing_box); if (dnsItem == null || dnsItem.Enabled == false) { @@ -89,12 +84,23 @@ public partial class CoreConfigSingboxService hostsDomains.Add(kvp.Key); } } + if (simpleDNSItem.UseSystemHosts == true) + { + var systemHostsMap = Utils.GetSystemHosts(); + foreach (var kvp in systemHostsMap) + { + hostsDomains.Add(kvp.Key); + } + } } - singboxConfig.route.rules.Add(new() + if (hostsDomains.Count > 0) { - action = "resolve", - domain = hostsDomains, - }); + singboxConfig.route.rules.Add(new() + { + action = "resolve", + domain = hostsDomains, + }); + } singboxConfig.route.rules.Add(new() { From 33d9c5db6c845a86c44dc4d2f12e4ffdeca242d4 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 13 Sep 2025 14:46:35 +0800 Subject: [PATCH 11/12] up GlobalUsings --- v2rayN/v2rayN.Desktop/App.axaml.cs | 1 - v2rayN/v2rayN.Desktop/Base/WindowBase.cs | 1 - v2rayN/v2rayN.Desktop/GlobalUsings.cs | 5 +++-- v2rayN/v2rayN.Desktop/Program.cs | 1 - v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs | 1 - v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs | 1 - v2rayN/v2rayN.Desktop/Views/DNSSettingWindow.axaml.cs | 1 - .../v2rayN.Desktop/Views/FullConfigTemplateWindow.axaml.cs | 1 - v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs | 1 - v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs | 1 - v2rayN/v2rayN.Desktop/Views/ProfilesSelectWindow.axaml.cs | 1 - v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs | 1 - v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs | 1 - v2rayN/v2rayN.Desktop/Views/SudoPasswordInputView.axaml.cs | 1 - v2rayN/v2rayN/App.xaml.cs | 1 - v2rayN/v2rayN/Base/WindowBase.cs | 1 - v2rayN/v2rayN/Converters/MaterialDesignFonts.cs | 1 - v2rayN/v2rayN/GlobalUsings.cs | 5 +++-- v2rayN/v2rayN/Manager/HotkeyManager.cs | 1 - v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs | 1 - v2rayN/v2rayN/Views/AddServer2Window.xaml.cs | 1 - v2rayN/v2rayN/Views/AddServerWindow.xaml.cs | 1 - v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs | 1 - v2rayN/v2rayN/Views/FullConfigTemplateWindow.xaml.cs | 1 - v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs | 1 - v2rayN/v2rayN/Views/MainWindow.xaml.cs | 1 - v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs | 1 - v2rayN/v2rayN/Views/ProfilesSelectWindow.xaml.cs | 1 - v2rayN/v2rayN/Views/ProfilesView.xaml.cs | 1 - v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs | 1 - v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs | 1 - v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs | 1 - v2rayN/v2rayN/Views/StatusBarView.xaml.cs | 1 - v2rayN/v2rayN/Views/SubEditWindow.xaml.cs | 1 - v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs | 1 - 35 files changed, 6 insertions(+), 37 deletions(-) diff --git a/v2rayN/v2rayN.Desktop/App.axaml.cs b/v2rayN/v2rayN.Desktop/App.axaml.cs index 5303eb6c..aa357ca4 100644 --- a/v2rayN/v2rayN.Desktop/App.axaml.cs +++ b/v2rayN/v2rayN.Desktop/App.axaml.cs @@ -1,7 +1,6 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; -using ServiceLib.Manager; using Splat; using v2rayN.Desktop.Common; using v2rayN.Desktop.Views; diff --git a/v2rayN/v2rayN.Desktop/Base/WindowBase.cs b/v2rayN/v2rayN.Desktop/Base/WindowBase.cs index c2c9a0bc..10105d2e 100644 --- a/v2rayN/v2rayN.Desktop/Base/WindowBase.cs +++ b/v2rayN/v2rayN.Desktop/Base/WindowBase.cs @@ -1,7 +1,6 @@ using Avalonia; using Avalonia.Interactivity; using Avalonia.ReactiveUI; -using ServiceLib.Manager; namespace v2rayN.Desktop.Base; diff --git a/v2rayN/v2rayN.Desktop/GlobalUsings.cs b/v2rayN/v2rayN.Desktop/GlobalUsings.cs index bc789ab0..4f2b931d 100644 --- a/v2rayN/v2rayN.Desktop/GlobalUsings.cs +++ b/v2rayN/v2rayN.Desktop/GlobalUsings.cs @@ -1,8 +1,9 @@ -global using ServiceLib; +global using ServiceLib; global using ServiceLib.Base; global using ServiceLib.Common; global using ServiceLib.Enums; global using ServiceLib.Handler; +global using ServiceLib.Manager; global using ServiceLib.Models; global using ServiceLib.Resx; -global using ServiceLib.ViewModels; \ No newline at end of file +global using ServiceLib.ViewModels; diff --git a/v2rayN/v2rayN.Desktop/Program.cs b/v2rayN/v2rayN.Desktop/Program.cs index 58ddb9f9..4b534324 100644 --- a/v2rayN/v2rayN.Desktop/Program.cs +++ b/v2rayN/v2rayN.Desktop/Program.cs @@ -1,6 +1,5 @@ using Avalonia; using Avalonia.ReactiveUI; -using ServiceLib.Manager; using v2rayN.Desktop.Common; namespace v2rayN.Desktop; diff --git a/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs b/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs index 21899bfc..3473cf23 100644 --- a/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs +++ b/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs @@ -8,7 +8,6 @@ using Avalonia.Styling; using ReactiveUI; using ReactiveUI.Fody.Helpers; using Semi.Avalonia; -using ServiceLib.Manager; namespace v2rayN.Desktop.ViewModels; diff --git a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs index 6880e23d..a42ab387 100644 --- a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs @@ -2,7 +2,6 @@ using System.Reactive.Disposables; using Avalonia.Controls; using Avalonia.Interactivity; using ReactiveUI; -using ServiceLib.Manager; using v2rayN.Desktop.Base; namespace v2rayN.Desktop.Views; diff --git a/v2rayN/v2rayN.Desktop/Views/DNSSettingWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/DNSSettingWindow.axaml.cs index 54f8e443..2718df95 100644 --- a/v2rayN/v2rayN.Desktop/Views/DNSSettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/DNSSettingWindow.axaml.cs @@ -2,7 +2,6 @@ using System.Reactive.Disposables; using Avalonia.Controls; using Avalonia.Interactivity; using ReactiveUI; -using ServiceLib.Manager; using v2rayN.Desktop.Base; namespace v2rayN.Desktop.Views; diff --git a/v2rayN/v2rayN.Desktop/Views/FullConfigTemplateWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/FullConfigTemplateWindow.axaml.cs index 38f3d34c..97bc4afb 100644 --- a/v2rayN/v2rayN.Desktop/Views/FullConfigTemplateWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/FullConfigTemplateWindow.axaml.cs @@ -1,7 +1,6 @@ using System.Reactive.Disposables; using Avalonia.Interactivity; using ReactiveUI; -using ServiceLib.Manager; using v2rayN.Desktop.Base; namespace v2rayN.Desktop.Views; diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index 582b18ac..d72c37a7 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -10,7 +10,6 @@ using Avalonia.Threading; using DialogHostAvalonia; using MsBox.Avalonia.Enums; using ReactiveUI; -using ServiceLib.Manager; using Splat; using v2rayN.Desktop.Base; using v2rayN.Desktop.Common; diff --git a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs index 6a313a35..7c251777 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs @@ -2,7 +2,6 @@ using System.Reactive.Disposables; using Avalonia.Controls; using Avalonia.Interactivity; using ReactiveUI; -using ServiceLib.Manager; using v2rayN.Desktop.Base; namespace v2rayN.Desktop.Views; diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesSelectWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesSelectWindow.axaml.cs index b3319154..d597e567 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesSelectWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesSelectWindow.axaml.cs @@ -6,7 +6,6 @@ using Avalonia.Interactivity; using Avalonia.ReactiveUI; using Avalonia.VisualTree; using ReactiveUI; -using ServiceLib.Manager; namespace v2rayN.Desktop.Views; diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs index c52cad9d..5bade399 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs @@ -8,7 +8,6 @@ using Avalonia.Threading; using DialogHostAvalonia; using MsBox.Avalonia.Enums; using ReactiveUI; -using ServiceLib.Manager; using Splat; using v2rayN.Desktop.Common; diff --git a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs index d90affe2..3eb08f96 100644 --- a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs @@ -6,7 +6,6 @@ using Avalonia.ReactiveUI; using Avalonia.Threading; using DialogHostAvalonia; using ReactiveUI; -using ServiceLib.Manager; using Splat; using v2rayN.Desktop.Common; diff --git a/v2rayN/v2rayN.Desktop/Views/SudoPasswordInputView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/SudoPasswordInputView.axaml.cs index 90b6ba76..a87d0deb 100644 --- a/v2rayN/v2rayN.Desktop/Views/SudoPasswordInputView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/SudoPasswordInputView.axaml.cs @@ -2,7 +2,6 @@ using Avalonia.Controls; using Avalonia.Threading; using CliWrap.Buffered; using DialogHostAvalonia; -using ServiceLib.Manager; namespace v2rayN.Desktop.Views; diff --git a/v2rayN/v2rayN/App.xaml.cs b/v2rayN/v2rayN/App.xaml.cs index 611fad72..b37b6986 100644 --- a/v2rayN/v2rayN/App.xaml.cs +++ b/v2rayN/v2rayN/App.xaml.cs @@ -1,7 +1,6 @@ using System.Diagnostics; using System.Windows; using System.Windows.Threading; -using ServiceLib.Manager; namespace v2rayN; diff --git a/v2rayN/v2rayN/Base/WindowBase.cs b/v2rayN/v2rayN/Base/WindowBase.cs index 3e1c3004..1c5b8cda 100644 --- a/v2rayN/v2rayN/Base/WindowBase.cs +++ b/v2rayN/v2rayN/Base/WindowBase.cs @@ -1,6 +1,5 @@ using System.Windows; using ReactiveUI; -using ServiceLib.Manager; namespace v2rayN.Base; diff --git a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs index 73fd5632..37b2e925 100644 --- a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs +++ b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs @@ -1,5 +1,4 @@ using System.Windows.Media; -using ServiceLib.Manager; namespace v2rayN.Converters; diff --git a/v2rayN/v2rayN/GlobalUsings.cs b/v2rayN/v2rayN/GlobalUsings.cs index bc789ab0..4f2b931d 100644 --- a/v2rayN/v2rayN/GlobalUsings.cs +++ b/v2rayN/v2rayN/GlobalUsings.cs @@ -1,8 +1,9 @@ -global using ServiceLib; +global using ServiceLib; global using ServiceLib.Base; global using ServiceLib.Common; global using ServiceLib.Enums; global using ServiceLib.Handler; +global using ServiceLib.Manager; global using ServiceLib.Models; global using ServiceLib.Resx; -global using ServiceLib.ViewModels; \ No newline at end of file +global using ServiceLib.ViewModels; diff --git a/v2rayN/v2rayN/Manager/HotkeyManager.cs b/v2rayN/v2rayN/Manager/HotkeyManager.cs index 9301cfad..538ce605 100644 --- a/v2rayN/v2rayN/Manager/HotkeyManager.cs +++ b/v2rayN/v2rayN/Manager/HotkeyManager.cs @@ -4,7 +4,6 @@ using System.Text; using System.Windows; using System.Windows.Input; using System.Windows.Interop; -using ServiceLib.Manager; namespace v2rayN.Manager; diff --git a/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs index a9bd4b06..38204778 100644 --- a/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs @@ -9,7 +9,6 @@ using MaterialDesignColors.ColorManipulation; using MaterialDesignThemes.Wpf; using ReactiveUI; using ReactiveUI.Fody.Helpers; -using ServiceLib.Manager; namespace v2rayN.ViewModels; diff --git a/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs b/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs index b455ecd4..b9c62dcd 100644 --- a/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs @@ -1,7 +1,6 @@ using System.Reactive.Disposables; using System.Windows; using ReactiveUI; -using ServiceLib.Manager; namespace v2rayN.Views; diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs index 75f1bd1c..2c0406d5 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs @@ -2,7 +2,6 @@ using System.Reactive.Disposables; using System.Windows; using System.Windows.Controls; using ReactiveUI; -using ServiceLib.Manager; namespace v2rayN.Views; diff --git a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs index 9df0cf2c..b5624662 100644 --- a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs @@ -1,7 +1,6 @@ using System.Reactive.Disposables; using System.Windows; using ReactiveUI; -using ServiceLib.Manager; namespace v2rayN.Views; diff --git a/v2rayN/v2rayN/Views/FullConfigTemplateWindow.xaml.cs b/v2rayN/v2rayN/Views/FullConfigTemplateWindow.xaml.cs index 583ccd22..7f3c3341 100644 --- a/v2rayN/v2rayN/Views/FullConfigTemplateWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/FullConfigTemplateWindow.xaml.cs @@ -1,7 +1,6 @@ using System.Reactive.Disposables; using System.Windows; using ReactiveUI; -using ServiceLib.Manager; namespace v2rayN.Views; diff --git a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs index 54dc6c8b..b23b2860 100644 --- a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs @@ -4,7 +4,6 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; using ReactiveUI; -using ServiceLib.Manager; using v2rayN.Manager; namespace v2rayN.Views; diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index a3a26c97..a804775e 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -9,7 +9,6 @@ using System.Windows.Media; using System.Windows.Threading; using MaterialDesignThemes.Wpf; using ReactiveUI; -using ServiceLib.Manager; using Splat; using v2rayN.Manager; diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index 16347710..31b43d9a 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -4,7 +4,6 @@ using System.Reactive.Disposables; using System.Windows; using System.Windows.Media; using ReactiveUI; -using ServiceLib.Manager; namespace v2rayN.Views; diff --git a/v2rayN/v2rayN/Views/ProfilesSelectWindow.xaml.cs b/v2rayN/v2rayN/Views/ProfilesSelectWindow.xaml.cs index c6c82928..6e3369df 100644 --- a/v2rayN/v2rayN/Views/ProfilesSelectWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/ProfilesSelectWindow.xaml.cs @@ -4,7 +4,6 @@ using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Input; using ReactiveUI; -using ServiceLib.Manager; using v2rayN.Base; namespace v2rayN.Views; diff --git a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs index 5f8f7033..8ef236ab 100644 --- a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs +++ b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs @@ -8,7 +8,6 @@ using System.Windows.Media; using System.Windows.Threading; using MaterialDesignThemes.Wpf; using ReactiveUI; -using ServiceLib.Manager; using Splat; using v2rayN.Base; using Point = System.Windows.Point; diff --git a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs index 0c1d2a91..d3e06cb3 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs @@ -1,7 +1,6 @@ using System.Reactive.Disposables; using System.Windows; using ReactiveUI; -using ServiceLib.Manager; namespace v2rayN.Views; diff --git a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs index 37bbce82..d69146d9 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs @@ -2,7 +2,6 @@ using System.Reactive.Disposables; using System.Windows; using System.Windows.Input; using ReactiveUI; -using ServiceLib.Manager; namespace v2rayN.Views; diff --git a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs index ee2ab9cb..e597715b 100644 --- a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs @@ -2,7 +2,6 @@ using System.Reactive.Disposables; using System.Windows; using System.Windows.Input; using ReactiveUI; -using ServiceLib.Manager; namespace v2rayN.Views; diff --git a/v2rayN/v2rayN/Views/StatusBarView.xaml.cs b/v2rayN/v2rayN/Views/StatusBarView.xaml.cs index 2bc4c7c9..8a3a5df4 100644 --- a/v2rayN/v2rayN/Views/StatusBarView.xaml.cs +++ b/v2rayN/v2rayN/Views/StatusBarView.xaml.cs @@ -3,7 +3,6 @@ using System.Windows; using System.Windows.Input; using System.Windows.Threading; using ReactiveUI; -using ServiceLib.Manager; using Splat; using v2rayN.Manager; diff --git a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs index e37076e7..b58f8d27 100644 --- a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs @@ -1,7 +1,6 @@ using System.Reactive.Disposables; using System.Windows; using ReactiveUI; -using ServiceLib.Manager; namespace v2rayN.Views; diff --git a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs index c8e694d4..9e8d0c76 100644 --- a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs @@ -4,7 +4,6 @@ using System.Windows; using System.Windows.Input; using MaterialDesignThemes.Wpf; using ReactiveUI; -using ServiceLib.Manager; namespace v2rayN.Views; From 4e042295d2651755b6e1fce436aa6c8e069646f9 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Sat, 13 Sep 2025 14:55:30 +0800 Subject: [PATCH 12/12] Add global fakeip and fakeip filter (#7919) --- v2rayN/ServiceLib/Global.cs | 1 + v2rayN/ServiceLib/Handler/ConfigHandler.cs | 5 + v2rayN/ServiceLib/Models/ConfigItems.cs | 1 + v2rayN/ServiceLib/Resx/ResUI.Designer.cs | 18 ++-- v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx | 6 +- v2rayN/ServiceLib/Resx/ResUI.hu.resx | 6 +- v2rayN/ServiceLib/Resx/ResUI.resx | 6 +- v2rayN/ServiceLib/Resx/ResUI.ru.resx | 6 +- v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx | 6 +- v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx | 6 +- .../ServiceLib/Sample/singbox_fakeip_filter | 92 +++++++++++++++++++ v2rayN/ServiceLib/ServiceLib.csproj | 1 + .../CoreConfig/Singbox/SingboxDnsService.cs | 35 ++++++- .../Views/DNSSettingWindow.axaml | 2 +- v2rayN/v2rayN/Views/DNSSettingWindow.xaml | 2 +- 15 files changed, 163 insertions(+), 30 deletions(-) create mode 100644 v2rayN/ServiceLib/Sample/singbox_fakeip_filter diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index a7c74c08..eb24d71e 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -40,6 +40,7 @@ public class Global public const string ProxySetLinuxShellFileName = NamespaceSample + "proxy_set_linux_sh"; public const string KillAsSudoOSXShellFileName = NamespaceSample + "kill_as_sudo_osx_sh"; public const string KillAsSudoLinuxShellFileName = NamespaceSample + "kill_as_sudo_linux_sh"; + public const string SingboxFakeIPFilterFileName = NamespaceSample + "singbox_fakeip_filter"; public const string DefaultSecurity = "auto"; public const string DefaultNetwork = "tcp"; diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index e488720f..786f3aff 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -113,6 +113,10 @@ public static class ConfigHandler config.ConstItem ??= new ConstItem(); config.SimpleDNSItem ??= InitBuiltinSimpleDNS(); + if (config.SimpleDNSItem.GlobalFakeIp is null) + { + config.SimpleDNSItem.GlobalFakeIp = true; + } config.SpeedTestItem ??= new(); if (config.SpeedTestItem.SpeedTestTimeout < 10) @@ -2221,6 +2225,7 @@ public static class ConfigHandler UseSystemHosts = false, AddCommonHosts = true, FakeIP = false, + GlobalFakeIp = true, BlockBindingQuery = true, DirectDNS = Global.DomainDirectDNSAddress.FirstOrDefault(), RemoteDNS = Global.DomainRemoteDNSAddress.FirstOrDefault(), diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/ConfigItems.cs index 148f2bd7..b9b305bb 100644 --- a/v2rayN/ServiceLib/Models/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/ConfigItems.cs @@ -260,6 +260,7 @@ public class SimpleDNSItem public bool? UseSystemHosts { get; set; } public bool? AddCommonHosts { get; set; } public bool? FakeIP { get; set; } + public bool? GlobalFakeIp { get; set; } public bool? BlockBindingQuery { get; set; } public string? DirectDNS { get; set; } public string? RemoteDNS { get; set; } diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 6503b41c..7e848cf0 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -2301,15 +2301,6 @@ namespace ServiceLib.Resx { } } - /// - /// 查找类似 Apply to Proxy Domains Only 的本地化字符串。 - /// - public static string TbApplyProxyDomainsOnly { - get { - return ResourceManager.GetString("TbApplyProxyDomainsOnly", resourceCulture); - } - } - /// /// 查找类似 Auto refresh 的本地化字符串。 /// @@ -2526,6 +2517,15 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 Applies globally by default, with built-in FakeIP filtering (sing-box only). 的本地化字符串。 + /// + public static string TbFakeIPTips { + get { + return ResourceManager.GetString("TbFakeIPTips", resourceCulture); + } + } + /// /// 查找类似 Fingerprint 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index 0c8ca393..f79901eb 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -1455,9 +1455,6 @@ DNS Hosts: ("domain1 ip1 ip2" per line) - - Apply to Proxy Domains Only - Basic DNS Settings @@ -1515,4 +1512,7 @@ Select Profile + + Applies globally by default, with built-in FakeIP filtering (sing-box only). + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx index 800fa00f..e801c796 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx @@ -1455,9 +1455,6 @@ DNS Hosts: ("domain1 ip1 ip2" per line) - - Apply to Proxy Domains Only - Basic DNS Settings @@ -1515,4 +1512,7 @@ Select Profile + + Applies globally by default, with built-in FakeIP filtering (sing-box only). + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 614c8092..fc4b218f 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1455,9 +1455,6 @@ DNS Hosts: ("domain1 ip1 ip2" per line) - - Apply to Proxy Domains Only - Basic DNS Settings @@ -1515,4 +1512,7 @@ Select Profile + + Applies globally by default, with built-in FakeIP filtering (sing-box only). + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index 294d9f34..04e16eb8 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -1455,9 +1455,6 @@ DNS hosts: (каждая строка в формате "domain1 ip1 ip2") - - Применять только к доменам через прокси - Базовые настройки DNS @@ -1515,4 +1512,7 @@ Select Profile + + Applies globally by default, with built-in FakeIP filtering (sing-box only). + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index 194a59e2..ced2d74b 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1452,9 +1452,6 @@ DNS Hosts:(“域名1 ip1 ip2” 一行一个) - - 仅对代理域名生效 - DNS 基础设置 @@ -1512,4 +1509,7 @@ 选择配置文件 + + 默认全局生效,内置 FakeIP 过滤,仅在 sing-box 中生效 + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index fa84c789..720b7269 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1452,9 +1452,6 @@ DNS Hosts: ("domain1 ip1 ip2" per line) - - Apply to Proxy Domains Only - Basic DNS Settings @@ -1512,4 +1509,7 @@ Select Profile + + Applies globally by default, with built-in FakeIP filtering (sing-box only). + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Sample/singbox_fakeip_filter b/v2rayN/ServiceLib/Sample/singbox_fakeip_filter new file mode 100644 index 00000000..860ab0eb --- /dev/null +++ b/v2rayN/ServiceLib/Sample/singbox_fakeip_filter @@ -0,0 +1,92 @@ +{ + "domain": [ + "amobile.music.tc.qq.com", + "api-jooxtt.sanook.com", + "api.joox.com", + "aqqmusic.tc.qq.com", + "dl.stream.qqmusic.qq.com", + "ff.dorado.sdo.com", + "heartbeat.belkin.com", + "isure.stream.qqmusic.qq.com", + "joox.com", + "lens.l.google.com", + "localhost.ptlogin2.qq.com", + "localhost.sec.qq.com", + "mesu.apple.com", + "mobileoc.music.tc.qq.com", + "music.taihe.com", + "musicapi.taihe.com", + "na.b.g-tun.com", + "proxy.golang.org", + "ps.res.netease.com", + "shark007.net", + "songsearch.kugou.com", + "static.adtidy.org", + "streamoc.music.tc.qq.com", + "swcdn.apple.com", + "swdist.apple.com", + "swdownload.apple.com", + "swquery.apple.com", + "swscan.apple.com", + "trackercdn.kugou.com", + "xnotify.xboxlive.com" + ], + "domain_keyword": [ + "ntp", + "stun", + "time" + ], + "domain_regex": [ + "^[^.]+$", + "^[^.]+\\.[^.]+\\.xboxlive\\.com$", + "^localhost\\.[^.]+\\.weixin\\.qq\\.com$", + "^mijia\\scloud$", + "^xbox\\.[^.]+\\.microsoft\\.com$", + "^xbox\\.[^.]+\\.[^.]+\\.microsoft\\.com$" + ], + "domain_suffix": [ + "126.net", + "3gppnetwork.org", + "battle.net", + "battlenet.com.cn", + "cdn.nintendo.net", + "cmbchina.com", + "cmbimg.com", + "ff14.sdo.com", + "ffxiv.com", + "finalfantasyxiv.com", + "gcloudcs.com", + "home.arpa", + "invalid", + "kuwo.cn", + "lan", + "linksys.com", + "linksyssmartwifi.com", + "local", + "localdomain", + "localhost", + "market.xiaomi.com", + "mcdn.bilivideo.cn", + "media.dssott.com", + "msftconnecttest.com", + "msftncsi.com", + "music.163.com", + "music.migu.cn", + "n0808.com", + "nflxvideo.net", + "oray.com", + "orayimg.com", + "router.asus.com", + "sandai.net", + "square-enix.com", + "srv.nintendo.net", + "steamcontent.com", + "uu.163.com", + "wargaming.net", + "wggames.cn", + "wotgame.cn", + "wowsgame.cn", + "xiami.com", + "y.qq.com" + ] +} \ No newline at end of file diff --git a/v2rayN/ServiceLib/ServiceLib.csproj b/v2rayN/ServiceLib/ServiceLib.csproj index ecbab780..7ee72196 100644 --- a/v2rayN/ServiceLib/ServiceLib.csproj +++ b/v2rayN/ServiceLib/ServiceLib.csproj @@ -44,6 +44,7 @@ + diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs index 306572a1..00bb14d9 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs @@ -33,6 +33,15 @@ public partial class CoreConfigSingboxService lastRule.Ip?.Contains("0.0.0.0/0") == true); } singboxConfig.dns.final = useDirectDns ? Global.SingboxDirectDNSTag : Global.SingboxRemoteDNSTag; + if ((!useDirectDns) && simpleDNSItem.FakeIP == true && simpleDNSItem.GlobalFakeIp == false) + { + singboxConfig.dns.rules.Add(new() + { + server = Global.SingboxFakeDNSTag, + query_type = new List { 1, 28 }, // A and AAAA + rewrite_ttl = 1, + }); + } // Tun2SocksAddress if (node != null && Utils.IsDomain(node.Address)) @@ -187,6 +196,28 @@ public partial class CoreConfigSingboxService }); } + if (simpleDNSItem.FakeIP == true && simpleDNSItem.GlobalFakeIp == true) + { + var fakeipFilterRule = JsonUtils.Deserialize(EmbedUtils.GetEmbedText(Global.SingboxFakeIPFilterFileName)); + fakeipFilterRule.invert = true; + var rule4Fake = new Rule4Sbox + { + server = Global.SingboxFakeDNSTag, + type = "logical", + mode = "and", + rewrite_ttl = 1, + rules = new List + { + new() { + query_type = new List { 1, 28 }, // A and AAAA + }, + fakeipFilterRule, + } + }; + + singboxConfig.dns.rules.Add(rule4Fake); + } + var routing = await ConfigHandler.GetDefaultRouting(_config); if (routing == null) return 0; @@ -266,10 +297,12 @@ public partial class CoreConfigSingboxService } else { - if (simpleDNSItem.FakeIP == true) + if (simpleDNSItem.FakeIP == true && simpleDNSItem.GlobalFakeIp == false) { var rule4Fake = JsonUtils.DeepCopy(rule); rule4Fake.server = Global.SingboxFakeDNSTag; + rule4Fake.query_type = new List { 1, 28 }; // A and AAAA + rule4Fake.rewrite_ttl = 1; singboxConfig.dns.rules.Add(rule4Fake); } rule.server = Global.SingboxRemoteDNSTag; diff --git a/v2rayN/v2rayN.Desktop/Views/DNSSettingWindow.axaml b/v2rayN/v2rayN.Desktop/Views/DNSSettingWindow.axaml index 18f294d3..d8eed12e 100644 --- a/v2rayN/v2rayN.Desktop/Views/DNSSettingWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/DNSSettingWindow.axaml @@ -229,7 +229,7 @@ Grid.Column="2" Margin="{StaticResource Margin4}" VerticalAlignment="Center" - Text="{x:Static resx:ResUI.TbApplyProxyDomainsOnly}" + Text="{x:Static resx:ResUI.TbFakeIPTips}" TextWrapping="Wrap" />