From 39ef5d81747f8015e68d6d874c42c72ae69d72db Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 20 Apr 2026 19:23:45 +0800 Subject: [PATCH] Default to first sub; update SubIndexId on delete https://github.com/2dust/v2rayN/issues/9151 --- v2rayN/ServiceLib/Handler/ConfigHandler.cs | 6 ++++++ v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs | 2 +- v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index a49f12f7..281db07d 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -1936,6 +1936,12 @@ public static class ConfigHandler await SQLiteHelper.Instance.DeleteAsync(item); await RemoveServersViaSubid(config, id, false); + if (item.Id == config.SubIndexId) + { + var subs = await AppManager.Instance.SubItems(); + config.SubIndexId = subs.LastOrDefault()?.Id; + } + return 0; } diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs index b3810b52..a4d9b298 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs @@ -190,7 +190,7 @@ public class ProfilesSelectViewModel : MyReactiveObject } SelectedSub = (_config.SubIndexId.IsNotEmpty() ? SubItems.FirstOrDefault(t => t.Id == _config.SubIndexId) - : null) ?? SubItems.LastOrDefault(); + : null) ?? SubItems.FirstOrDefault(); } private async Task?> GetProfileItemsEx(string subid, string filter) diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index 7a127fa7..f44f52e3 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -393,7 +393,7 @@ public class ProfilesViewModel : MyReactiveObject } SelectedSub = (_config.SubIndexId.IsNotEmpty() ? SubItems.FirstOrDefault(t => t.Id == _config.SubIndexId) - : null) ?? SubItems.LastOrDefault(); + : null) ?? SubItems.FirstOrDefault(); } private async Task?> GetProfileItemsEx(string subid, string filter)