From 9326a4ad797377775ecfb53b18275043ee3e0979 Mon Sep 17 00:00:00 2001 From: Vinny Date: Fri, 8 May 2026 07:42:26 +0300 Subject: [PATCH] Persist message auto-scroll setting --- v2rayN/ServiceLib/Models/ConfigItems.cs | 1 + v2rayN/ServiceLib/ViewModels/MsgViewModel.cs | 15 ++++++++++++--- v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs | 3 ++- v2rayN/v2rayN/Views/MsgView.xaml.cs | 3 ++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/ConfigItems.cs index b23a8fc3..4f71bad2 100644 --- a/v2rayN/ServiceLib/Models/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/ConfigItems.cs @@ -83,6 +83,7 @@ public class MsgUIItem { public string? MainMsgFilter { get; set; } public bool? AutoRefresh { get; set; } + public bool? AutoScrollToEnd { get; set; } } [Serializable] diff --git a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs index fbe06cb0..7dc4290d 100644 --- a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs @@ -13,21 +13,30 @@ public class MsgViewModel : MyReactiveObject [Reactive] public bool AutoRefresh { get; set; } + [Reactive] + public bool AutoScrollToEnd { get; set; } + public MsgViewModel(Func>? updateView) { _config = AppManager.Instance.Config; _updateView = updateView; MsgFilter = _config.MsgUIItem.MainMsgFilter ?? string.Empty; AutoRefresh = _config.MsgUIItem.AutoRefresh ?? true; + AutoScrollToEnd = _config.MsgUIItem.AutoScrollToEnd ?? true; this.WhenAnyValue( x => x.MsgFilter) .Subscribe(c => DoMsgFilter()); this.WhenAnyValue( - x => x.AutoRefresh, - y => y == true) - .Subscribe(c => _config.MsgUIItem.AutoRefresh = AutoRefresh); + x => x.AutoRefresh, + y => y == true) + .Subscribe(c => _config.MsgUIItem.AutoRefresh = AutoRefresh); + + this.WhenAnyValue( + x => x.AutoScrollToEnd, + y => y == true) + .Subscribe(c => _config.MsgUIItem.AutoScrollToEnd = AutoScrollToEnd); AppEvents.SendMsgViewRequested .AsObservable() diff --git a/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs index 78b0a4a1..85246d05 100644 --- a/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs @@ -16,6 +16,7 @@ public partial class MsgView : ReactiveUserControl { this.Bind(ViewModel, vm => vm.MsgFilter, v => v.cmbMsgFilter.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.AutoRefresh, v => v.togAutoRefresh.IsChecked).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.AutoScrollToEnd, v => v.togScrollToEnd.IsChecked).DisposeWith(disposables); }); TextEditorKeywordHighlighter.Attach(txtMsg, Global.LogLevelColors.ToDictionary( @@ -55,7 +56,7 @@ public partial class MsgView : ReactiveUserControl } txtMsg.AppendText(msg.ToString()); - if (togScrollToEnd.IsChecked ?? true) + if (ViewModel?.AutoScrollToEnd == true) { txtMsg.ScrollToEnd(); } diff --git a/v2rayN/v2rayN/Views/MsgView.xaml.cs b/v2rayN/v2rayN/Views/MsgView.xaml.cs index bccb4a5e..e226397e 100644 --- a/v2rayN/v2rayN/Views/MsgView.xaml.cs +++ b/v2rayN/v2rayN/Views/MsgView.xaml.cs @@ -12,6 +12,7 @@ public partial class MsgView { this.Bind(ViewModel, vm => vm.MsgFilter, v => v.cmbMsgFilter.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.AutoRefresh, v => v.togAutoRefresh.IsChecked).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.AutoScrollToEnd, v => v.togScrollToEnd.IsChecked).DisposeWith(disposables); }); btnCopy.Click += menuMsgViewCopyAll_Click; @@ -51,7 +52,7 @@ public partial class MsgView } txtMsg.AppendText(msg.ToString()); - if (togScrollToEnd.IsChecked ?? true) + if (ViewModel?.AutoScrollToEnd == true) { txtMsg.ScrollToEnd(); }