diff --git a/v2rayN/ServiceLib/Handler/AppEvents.cs b/v2rayN/ServiceLib/Handler/AppEvents.cs index 1cf3204b..ccc4e5cb 100644 --- a/v2rayN/ServiceLib/Handler/AppEvents.cs +++ b/v2rayN/ServiceLib/Handler/AppEvents.cs @@ -9,6 +9,8 @@ public static class AppEvents public static readonly Subject SubscriptionsRefreshRequested = new(); + public static readonly Subject ProxiesReloadRequested = new(); + public static readonly Subject SendSnackMsgRequested = new(); public static readonly Subject SendMsgViewRequested = new(); diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index 343d49df..bf999d12 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -69,6 +69,8 @@ public class ClashProxiesViewModel : MyReactiveObject SortingSelected = _config.ClashUIItem.ProxiesSorting; RuleModeSelected = (int)_config.ClashUIItem.RuleMode; + #region WhenAnyValue && ReactiveCommand + this.WhenAnyValue( x => x.SelectedGroup, y => y != null && y.Name.IsNotEmpty()) @@ -89,6 +91,17 @@ public class ClashProxiesViewModel : MyReactiveObject y => y == true) .Subscribe(c => { _config.ClashUIItem.ProxiesAutoRefresh = AutoRefresh; }); + #endregion WhenAnyValue && ReactiveCommand + + #region AppEvents + + AppEvents.ProxiesReloadRequested + .AsObservable() + .ObserveOn(RxApp.MainThreadScheduler) + .Subscribe(async _ => await ProxiesReload()); + + #endregion AppEvents + _ = Init(); } diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 4bc9997d..249a4322 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -520,7 +520,13 @@ public class MainWindowViewModel : MyReactiveObject }); Locator.Current.GetService()?.TestServerAvailability(); - RxApp.MainThreadScheduler.Schedule(() => _ = ReloadResult()); + var showClashUI = _config.IsRunningCore(ECoreType.sing_box); + if (showClashUI) + { + AppEvents.ProxiesReloadRequested.OnNext(Unit.Default); + } + + RxApp.MainThreadScheduler.Schedule(() => ReloadResult(showClashUI)); BlReloadEnabled = true; if (_hasNextReloadJob) @@ -530,19 +536,11 @@ public class MainWindowViewModel : MyReactiveObject } } - public async Task ReloadResult() + private void ReloadResult(bool showClashUI) { // BlReloadEnabled = true; - //Locator.Current.GetService()?.ChangeSystemProxyAsync(_config.systemProxyItem.sysProxyType, false); - ShowClashUI = _config.IsRunningCore(ECoreType.sing_box); - if (ShowClashUI) - { - Locator.Current.GetService()?.ProxiesReload(); - } - else - { - TabMainSelectedIndex = 0; - } + ShowClashUI = showClashUI; + TabMainSelectedIndex = showClashUI ? TabMainSelectedIndex : 0; } private async Task LoadCore() diff --git a/v2rayN/v2rayN.Desktop/Views/ClashProxiesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ClashProxiesView.axaml.cs index 754dd2a1..c8e7aeba 100644 --- a/v2rayN/v2rayN.Desktop/Views/ClashProxiesView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ClashProxiesView.axaml.cs @@ -3,7 +3,6 @@ using Avalonia.Input; using Avalonia.ReactiveUI; using DynamicData; using ReactiveUI; -using Splat; namespace v2rayN.Desktop.Views; @@ -13,7 +12,6 @@ public partial class ClashProxiesView : ReactiveUserControl ViewModel, typeof(ClashProxiesViewModel)); lstProxyDetails.DoubleTapped += LstProxyDetails_DoubleTapped; this.KeyDown += ClashProxiesView_KeyDown; diff --git a/v2rayN/v2rayN/Views/ClashProxiesView.xaml.cs b/v2rayN/v2rayN/Views/ClashProxiesView.xaml.cs index eff95de9..23943da1 100644 --- a/v2rayN/v2rayN/Views/ClashProxiesView.xaml.cs +++ b/v2rayN/v2rayN/Views/ClashProxiesView.xaml.cs @@ -1,7 +1,6 @@ using System.Reactive.Disposables; using System.Windows.Input; using ReactiveUI; -using Splat; namespace v2rayN.Views; @@ -14,7 +13,6 @@ public partial class ClashProxiesView { InitializeComponent(); ViewModel = new ClashProxiesViewModel(UpdateViewHandler); - Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(ClashProxiesViewModel)); lstProxyDetails.PreviewMouseDoubleClick += lstProxyDetails_PreviewMouseDoubleClick; this.WhenActivated(disposables =>