diff --git a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs index e2a8a3ce..1db559b4 100644 --- a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs @@ -43,14 +43,14 @@ public class CheckUpdateViewModel : MyReactiveObject private void RefreshCheckUpdateItems() { + var models = CoreInfoManager.Instance.GetCheckUpdateCoreTypes() + .Select(t => GetCheckUpdateModel(t)) + .ToList(); + + models.Add(GetGeoFileCheckUpdateModel()); + CheckUpdateModels.Clear(); - - foreach (var type in CoreInfoManager.Instance.GetCheckUpdateCoreTypes()) - { - CheckUpdateModels.Add(GetCheckUpdateModel(type)); - } - - CheckUpdateModels.Add(GetGeoFileCheckUpdateModel()); + CheckUpdateModels.AddRange(models); } private CheckUpdateModel GetCheckUpdateModel(ECoreType coreType) diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index 84442e57..f327c4df 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -187,6 +187,7 @@ public class ClashProxiesViewModel : MyReactiveObject var selectedName = SelectedGroup?.Name; ProxyGroups.Clear(); + var lstProxyGroups = new List(); var proxyGroups = ClashApiManager.Instance.GetClashProxyGroups(); if (proxyGroups is { Count: > 0 }) { @@ -200,7 +201,7 @@ public class ClashProxiesViewModel : MyReactiveObject { continue; } - ProxyGroups.Add(new ClashProxyModel() + lstProxyGroups.Add(new ClashProxyModel() { Now = item.now, Name = item.name, @@ -216,12 +217,12 @@ public class ClashProxiesViewModel : MyReactiveObject { continue; } - var item = ProxyGroups.FirstOrDefault(t => t.Name == kv.Key); + var item = lstProxyGroups.FirstOrDefault(t => t.Name == kv.Key); if (item != null && item.Name.IsNotEmpty()) { continue; } - ProxyGroups.Add(new ClashProxyModel() + lstProxyGroups.Add(new ClashProxyModel() { Now = kv.Value.now, Name = kv.Key, @@ -229,6 +230,8 @@ public class ClashProxiesViewModel : MyReactiveObject }); } + ProxyGroups.AddRange(lstProxyGroups); + if (ProxyGroups is { Count: > 0 }) { if (selectedName != null && ProxyGroups.Any(t => t.Name == selectedName)) diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs index f0d40024..b9a52936 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs @@ -161,19 +161,17 @@ public class ProfilesSelectViewModel : MyReactiveObject await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null); } - public async Task RefreshSubscriptions() + private async Task RefreshSubscriptions() { + var subItems = await AppManager.Instance.SubItems(); + subItems.Insert(0, new SubItem { Remarks = ResUI.AllGroupServers }); + SubItems.Clear(); + SubItems.AddRange(subItems); - SubItems.Add(new SubItem { Remarks = ResUI.AllGroupServers }); - - foreach (var item in await AppManager.Instance.SubItems()) - { - SubItems.Add(item); - } SelectedSub = (_config.SubIndexId.IsNotEmpty() - ? SubItems.FirstOrDefault(t => t.Id == _config.SubIndexId) - : null) ?? SubItems.FirstOrDefault(); + ? subItems.FirstOrDefault(t => t.Id == _config.SubIndexId) + : 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 981dd250..47dfc91c 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -397,17 +397,15 @@ public class ProfilesViewModel : MyReactiveObject private async Task RefreshSubscriptions() { + var subItems = await AppManager.Instance.SubItems(); + subItems.Insert(0, new SubItem { Remarks = ResUI.AllGroupServers }); + SubItems.Clear(); + SubItems.AddRange(subItems); - SubItems.Add(new SubItem { Remarks = ResUI.AllGroupServers }); - - foreach (var item in await AppManager.Instance.SubItems()) - { - SubItems.Add(item); - } SelectedSub = (_config.SubIndexId.IsNotEmpty() - ? SubItems.FirstOrDefault(t => t.Id == _config.SubIndexId) - : null) ?? SubItems.FirstOrDefault(); + ? subItems.FirstOrDefault(t => t.Id == _config.SubIndexId) + : null) ?? subItems.FirstOrDefault(); } private async Task?> GetProfileItemsEx(string subid, string filter) diff --git a/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs index 172a907d..bdcbfe94 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs @@ -95,6 +95,7 @@ public class RoutingRuleSettingViewModel : MyReactiveObject { RulesItems.Clear(); + var models = new List(); foreach (var item in _rules) { var it = new RulesItemModel() @@ -110,8 +111,9 @@ public class RoutingRuleSettingViewModel : MyReactiveObject Enabled = item.Enabled, Remarks = item.Remarks, }; - RulesItems.Add(it); + models.Add(it); } + RulesItems.AddRange(models); } public async Task RuleEditAsync(bool blNew) diff --git a/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs index 2075bb1e..13703ae7 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs @@ -83,6 +83,7 @@ public class RoutingSettingViewModel : MyReactiveObject public async Task RefreshRoutingItems() { RoutingItems.Clear(); + var models = new List(); var routings = await AppManager.Instance.RoutingItems(); foreach (var item in routings) @@ -98,8 +99,9 @@ public class RoutingSettingViewModel : MyReactiveObject CustomRulesetPath4Singbox = item.CustomRulesetPath4Singbox, Sort = item.Sort, }; - RoutingItems.Add(it); + models.Add(it); } + RoutingItems.AddRange(models); } /// diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index b3199f12..ce0486c4 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -234,6 +234,8 @@ public class StatusBarViewModel : MyReactiveObject await RefreshRoutingsMenu(); await InboundDisplayStatus(); await ChangeSystemProxyAsync(_config.SystemProxyItem.SysProxyType, true); + + BlRouting = true; } public void InitUpdateView(Func>? updateView) @@ -312,18 +314,20 @@ public class StatusBarViewModel : MyReactiveObject return; } + var models = new List(); BlServers = true; foreach (var it in lstModel) { var name = it.GetSummary(); var item = new ComboItem() { ID = it.IndexId, Text = name }; - Servers.Add(item); + models.Add(item); if (_config.IndexId == it.IndexId) { SelectedServer = item; } } + Servers.AddRange(models); } private void ServerSelectedChanged(bool c) @@ -408,18 +412,12 @@ public class StatusBarViewModel : MyReactiveObject private async Task RefreshRoutingsMenu() { - RoutingItems.Clear(); - - BlRouting = true; var routings = await AppManager.Instance.RoutingItems(); - foreach (var item in routings) - { - RoutingItems.Add(item); - if (item.IsActive) - { - SelectedRouting = item; - } - } + + RoutingItems.Clear(); + RoutingItems.AddRange(routings); + + SelectedRouting = routings.FirstOrDefault(t => t.IsActive == true); } private async Task RoutingSelectedChangedAsync(bool c)