From e6af9ab34236bd5f59c2419392341138e10e33b3 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 13 Mar 2026 10:36:58 +0800 Subject: [PATCH] Fix https://github.com/2dust/v2rayN/issues/8916 --- .../ServiceLib/ViewModels/ProfilesSelectViewModel.cs | 11 +++-------- v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs | 11 +++-------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs index eb010c58..b3810b52 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs @@ -188,14 +188,9 @@ public class ProfilesSelectViewModel : MyReactiveObject { SubItems.Add(item); } - if (_subIndexId != null && SubItems.FirstOrDefault(t => t.Id == _subIndexId) != null) - { - SelectedSub = SubItems.FirstOrDefault(t => t.Id == _subIndexId); - } - else - { - SelectedSub = SubItems.First(); - } + SelectedSub = (_config.SubIndexId.IsNotEmpty() + ? SubItems.FirstOrDefault(t => t.Id == _config.SubIndexId) + : null) ?? SubItems.LastOrDefault(); } private async Task?> GetProfileItemsEx(string subid, string filter) diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index 7700d416..6e7e183c 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -391,14 +391,9 @@ public class ProfilesViewModel : MyReactiveObject { SubItems.Add(item); } - if (_config.SubIndexId != null && SubItems.FirstOrDefault(t => t.Id == _config.SubIndexId) != null) - { - SelectedSub = SubItems.FirstOrDefault(t => t.Id == _config.SubIndexId); - } - else - { - SelectedSub = SubItems.First(); - } + SelectedSub = (_config.SubIndexId.IsNotEmpty() + ? SubItems.FirstOrDefault(t => t.Id == _config.SubIndexId) + : null) ?? SubItems.LastOrDefault(); } private async Task?> GetProfileItemsEx(string subid, string filter)