mirror of https://github.com/2dust/v2rayN
Optimization and improvement, using event subscribers
parent
721d70c8c7
commit
6929886b3e
|
@ -9,6 +9,8 @@ public static class AppEvents
|
|||
|
||||
public static readonly Subject<Unit> SubscriptionsRefreshRequested = new();
|
||||
|
||||
public static readonly Subject<Unit> ProxiesReloadRequested = new();
|
||||
|
||||
public static readonly Subject<string> SendSnackMsgRequested = new();
|
||||
|
||||
public static readonly Subject<string> SendMsgViewRequested = new();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -520,7 +520,13 @@ public class MainWindowViewModel : MyReactiveObject
|
|||
});
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.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<StatusBarViewModel>()?.ChangeSystemProxyAsync(_config.systemProxyItem.sysProxyType, false);
|
||||
ShowClashUI = _config.IsRunningCore(ECoreType.sing_box);
|
||||
if (ShowClashUI)
|
||||
{
|
||||
Locator.Current.GetService<ClashProxiesViewModel>()?.ProxiesReload();
|
||||
}
|
||||
else
|
||||
{
|
||||
TabMainSelectedIndex = 0;
|
||||
}
|
||||
ShowClashUI = showClashUI;
|
||||
TabMainSelectedIndex = showClashUI ? TabMainSelectedIndex : 0;
|
||||
}
|
||||
|
||||
private async Task LoadCore()
|
||||
|
|
|
@ -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<ClashProxiesViewMode
|
|||
{
|
||||
InitializeComponent();
|
||||
ViewModel = new ClashProxiesViewModel(UpdateViewHandler);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(ClashProxiesViewModel));
|
||||
lstProxyDetails.DoubleTapped += LstProxyDetails_DoubleTapped;
|
||||
this.KeyDown += ClashProxiesView_KeyDown;
|
||||
|
||||
|
|
|
@ -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 =>
|
||||
|
|
Loading…
Reference in New Issue