From 35ca3b1eae76c995501b5909866b2663893f5284 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 9040d70c..c70d598d 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -2098,18 +2098,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); @@ -2117,6 +2137,7 @@ public class ConfigHandler { Remarks = "sing-box", CoreType = ECoreType.sing_box, + Enabled = false, }; await SaveDNSItems(config, item2); }