diff --git a/v2rayN/ServiceLib/Enums/EViewAction.cs b/v2rayN/ServiceLib/Enums/EViewAction.cs index c4689c9a..7677c6e9 100644 --- a/v2rayN/ServiceLib/Enums/EViewAction.cs +++ b/v2rayN/ServiceLib/Enums/EViewAction.cs @@ -6,7 +6,6 @@ public enum EViewAction ShowYesNo, SaveFileDialog, AddBatchRoutingRulesYesNo, - AdjustMainLvColWidth, SetClipboardData, AddServerViaClipboard, ImportRulesFromClipboard, diff --git a/v2rayN/ServiceLib/Handler/AppEvents.cs b/v2rayN/ServiceLib/Handler/AppEvents.cs index a651365d..f61053ae 100644 --- a/v2rayN/ServiceLib/Handler/AppEvents.cs +++ b/v2rayN/ServiceLib/Handler/AppEvents.cs @@ -13,5 +13,7 @@ public static class AppEvents public static readonly Subject AppExitRequested = new(); + public static readonly Subject AdjustMainLvColWidthRequested = new(); + public static readonly Subject DispatcherStatisticsRequested = new(); } diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index fa5dc82b..45b8ffa7 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -268,7 +268,7 @@ public class MainWindowViewModel : MyReactiveObject } if (_config.UiItem.EnableAutoAdjustMainLvColWidth) { - _updateView?.Invoke(EViewAction.AdjustMainLvColWidth, null); + AppEvents.AdjustMainLvColWidthRequested.OnNext(Unit.Default); } } } diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index 10ec4b4b..058855a8 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -348,11 +348,6 @@ public class ProfilesViewModel : MyReactiveObject } } - public async Task AutofitColumnWidthAsync() - { - await _updateView?.Invoke(EViewAction.AdjustMainLvColWidth, null); - } - #endregion Actions #region Servers && Groups diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index cc769c79..417bbb9f 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -250,12 +250,6 @@ public partial class MainWindow : WindowBase await ViewModel.AddServerViaClipboardAsync(clipboardData); } break; - - case EViewAction.AdjustMainLvColWidth: - Dispatcher.UIThread.Post(() => - Locator.Current.GetService()?.AutofitColumnWidthAsync(), - DispatcherPriority.Default); - break; } return await Task.FromResult(true); diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs index 733a2194..994b0342 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs @@ -103,6 +103,12 @@ public partial class ProfilesView : ReactiveUserControl .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => StorageUI()) .DisposeWith(disposables); + + AppEvents.AdjustMainLvColWidthRequested + .AsObservable() + .ObserveOn(RxApp.MainThreadScheduler) + .Subscribe(_ => AutofitColumnWidth()) + .DisposeWith(disposables); }); RestoreUI(); @@ -133,13 +139,6 @@ public partial class ProfilesView : ReactiveUserControl await AvaUtils.SetClipboardData(this, (string)obj); break; - case EViewAction.AdjustMainLvColWidth: - Dispatcher.UIThread.Post(() => - AutofitColumnWidth(), - DispatcherPriority.Default); - - break; - case EViewAction.ProfilesFocus: lstProfiles.Focus(); break; diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index 4c35d2e9..b9868edf 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -234,13 +234,6 @@ public partial class MainWindow ViewModel?.AddServerViaClipboardAsync(clipboardData); } break; - - case EViewAction.AdjustMainLvColWidth: - Application.Current?.Dispatcher.Invoke((() => - { - Locator.Current.GetService()?.AutofitColumnWidthAsync(); - }), DispatcherPriority.Normal); - break; } return await Task.FromResult(true); diff --git a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs index 0248a53a..539886a8 100644 --- a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs +++ b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs @@ -97,6 +97,12 @@ public partial class ProfilesView .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => StorageUI()) .DisposeWith(disposables); + + AppEvents.AdjustMainLvColWidthRequested + .AsObservable() + .ObserveOn(RxApp.MainThreadScheduler) + .Subscribe(_ => AutofitColumnWidth()) + .DisposeWith(disposables); }); RestoreUI(); @@ -113,14 +119,7 @@ public partial class ProfilesView if (obj is null) return false; WindowsUtils.SetClipboardData((string)obj); - break; - - case EViewAction.AdjustMainLvColWidth: - Application.Current?.Dispatcher.Invoke((() => - { - AutofitColumnWidth(); - }), DispatcherPriority.Normal); - break; + break; case EViewAction.ProfilesFocus: lstProfiles.Focus();