diff --git a/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml b/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml index 21bad138..6a9b7088 100644 --- a/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml +++ b/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml @@ -74,23 +74,28 @@ + Header="{x:Static resx:ResUI.TbSortingHost}" + Tag="Host" /> + Header="{x:Static resx:ResUI.TbSortingChain}" + Tag="Chain" /> + Header="{x:Static resx:ResUI.TbSortingNetwork}" + Tag="Network" /> + Header="{x:Static resx:ResUI.TbSortingType}" + Tag="Type" /> + Header="{x:Static resx:ResUI.TbSortingTime}" + Tag="Elapsed" /> diff --git a/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml.cs index 1c39df72..23722ad0 100644 --- a/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml.cs @@ -2,9 +2,15 @@ namespace v2rayN.Desktop.Views; public partial class ClashConnectionsView : ReactiveUserControl { + private static Config _config; + private static readonly string _tag = "ClashConnectionsView"; + public ClashConnectionsView() { InitializeComponent(); + + _config = AppManager.Instance.Config; + ViewModel = new ClashConnectionsViewModel(UpdateViewHandler); btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click; @@ -19,7 +25,15 @@ public partial class ClashConnectionsView : ReactiveUserControl vm.HostFilter, v => v.txtHostFilter.Text).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ConnectionCloseAllCmd, v => v.btnConnectionCloseAll).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.AutoRefresh, v => v.togAutoRefresh.IsChecked).DisposeWith(disposables); + + AppEvents.AppExitRequested + .AsObservable() + .ObserveOn(RxApp.MainThreadScheduler) + .Subscribe(_ => StorageUI()) + .DisposeWith(disposables); }); + + RestoreUI(); } private async Task UpdateViewHandler(EViewAction action, object? obj) @@ -51,4 +65,74 @@ public partial class ClashConnectionsView : ReactiveUserControl t.Index).ToList(); + if (lvColumnItem == null) + { + return; + } + + var displayIndex = 0; + foreach (var item in lvColumnItem) + { + foreach (var item2 in lstConnections.Columns) + { + if (item2.Tag == null) + { + continue; + } + if (item2.Tag.Equals(item.Name)) + { + if (item.Width < 0) + { + item2.IsVisible = false; + } + else + { + item2.Width = new DataGridLength(item.Width, DataGridLengthUnitType.Pixel); + item2.DisplayIndex = displayIndex++; + } + } + } + } + } + catch (Exception ex) + { + Logging.SaveLog(_tag, ex); + } + } + + private void StorageUI() + { + try + { + List lvColumnItem = new(); + foreach (var item2 in lstConnections.Columns) + { + if (item2.Tag == null) + { + continue; + } + lvColumnItem.Add(new() + { + Name = (string)item2.Tag, + Width = (int)(item2.IsVisible == true ? item2.ActualWidth : -1), + Index = item2.DisplayIndex + }); + } + _config.ClashUIItem.ConnectionsColumnItem = lvColumnItem; + } + catch (Exception ex) + { + Logging.SaveLog(_tag, ex); + } + } + + #endregion UI } diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs index 4ca8e793..40336be5 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs @@ -7,6 +7,7 @@ public partial class ProfilesView : ReactiveUserControl { private static Config _config; private Window? _window; + private static readonly string _tag = "ProfilesView"; public ProfilesView() { @@ -381,7 +382,7 @@ public partial class ProfilesView : ReactiveUserControl } catch (Exception ex) { - Logging.SaveLog("ProfilesView", ex); + Logging.SaveLog(_tag, ex); } } @@ -399,53 +400,67 @@ public partial class ProfilesView : ReactiveUserControl private void RestoreUI() { - var lvColumnItem = _config.UiItem.MainColumnItem.OrderBy(t => t.Index).ToList(); - var displayIndex = 0; - foreach (var item in lvColumnItem) + try { + var lvColumnItem = _config.UiItem.MainColumnItem.OrderBy(t => t.Index).ToList(); + var displayIndex = 0; + foreach (var item in lvColumnItem) + { + foreach (var item2 in lstProfiles.Columns) + { + if (item2.Tag == null) + { + continue; + } + if (item2.Tag.Equals(item.Name)) + { + if (item.Width < 0) + { + item2.IsVisible = false; + } + else + { + item2.Width = new DataGridLength(item.Width, DataGridLengthUnitType.Pixel); + item2.DisplayIndex = displayIndex++; + } + if (item.Name.ToLower().StartsWith("to")) + { + item2.IsVisible = _config.GuiItem.EnableStatistics; + } + } + } + } + } + catch (Exception ex) + { + Logging.SaveLog(_tag, ex); + } + } + + private void StorageUI() + { + try + { + List lvColumnItem = new(); foreach (var item2 in lstProfiles.Columns) { if (item2.Tag == null) { continue; } - if (item2.Tag.Equals(item.Name)) + lvColumnItem.Add(new() { - if (item.Width < 0) - { - item2.IsVisible = false; - } - else - { - item2.Width = new DataGridLength(item.Width, DataGridLengthUnitType.Pixel); - item2.DisplayIndex = displayIndex++; - } - if (item.Name.ToLower().StartsWith("to")) - { - item2.IsVisible = _config.GuiItem.EnableStatistics; - } - } + Name = (string)item2.Tag, + Width = (int)(item2.IsVisible == true ? item2.ActualWidth : -1), + Index = item2.DisplayIndex + }); } + _config.UiItem.MainColumnItem = lvColumnItem; } - } - - private void StorageUI() - { - List lvColumnItem = new(); - foreach (var item2 in lstProfiles.Columns) + catch (Exception ex) { - if (item2.Tag == null) - { - continue; - } - lvColumnItem.Add(new() - { - Name = (string)item2.Tag, - Width = (int)(item2.IsVisible == true ? item2.ActualWidth : -1), - Index = item2.DisplayIndex - }); + Logging.SaveLog(_tag, ex); } - _config.UiItem.MainColumnItem = lvColumnItem; } #endregion UI