auto-disable DNS items with empty NormalDNS on startup

DHR60 2025-07-28 19:59:22 +08:00
parent a90fb8eed4
commit 118927e43f
1 changed files with 21 additions and 0 deletions

View File

@ -2098,18 +2098,38 @@ public class ConfigHandler
/// <summary>
/// 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
/// </summary>
/// <param name="config">Current configuration</param>
/// <returns>0 if successful</returns>
public static async Task<int> 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);
}