From 7eaee59c48504cd32dbcbbc9072264af6a3656f8 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Mon, 28 Jul 2025 19:59:22 +0800 Subject: [PATCH] auto-disable DNS items with empty NormalDNS on startup --- v2rayN/ServiceLib/Handler/ConfigHandler.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index 0b4ee4b8..998c2427 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -2099,18 +2099,38 @@ public class ConfigHandler /// /// Initialize built-in DNS configurations /// Creates default DNS items for V2Ray and sing-box + /// Also checks existing DNS items and disables those with empty NormalDNS /// /// Current configuration /// 0 if successful public static async Task InitBuiltinDNS(Config config) { var items = await AppHandler.Instance.DNSItems(); + + // Check existing DNS items and disable those with empty NormalDNS + var needsUpdate = false; + foreach (var existingItem in items) + { + if (existingItem.NormalDNS.IsNullOrEmpty() && existingItem.Enabled) + { + existingItem.Enabled = false; + needsUpdate = true; + } + } + + // Update items if any changes were made + if (needsUpdate) + { + await SQLiteHelper.Instance.UpdateAllAsync(items); + } + if (items.Count <= 0) { var item = new DNSItem() { Remarks = "V2ray", CoreType = ECoreType.Xray, + Enabled = false, }; await SaveDNSItems(config, item); @@ -2118,6 +2138,7 @@ public class ConfigHandler { Remarks = "sing-box", CoreType = ECoreType.sing_box, + Enabled = false, }; await SaveDNSItems(config, item2); }