mirror of https://github.com/2dust/v2rayN
Optimization and improvement, using event subscribers
parent
18ac76e683
commit
27b45aee83
|
@ -7,6 +7,8 @@ public static class AppEvents
|
|||
{
|
||||
public static readonly Subject<Unit> ProfilesRefreshRequested = new();
|
||||
|
||||
public static readonly Subject<Unit> SubscriptionsRefreshRequested = new();
|
||||
|
||||
public static readonly Subject<string> SendSnackMsgRequested = new();
|
||||
|
||||
public static readonly Subject<string> SendMsgViewRequested = new();
|
||||
|
@ -18,4 +20,6 @@ public static class AppEvents
|
|||
public static readonly Subject<Unit> AdjustMainLvColWidthRequested = new();
|
||||
|
||||
public static readonly Subject<ServerSpeedItem> DispatcherStatisticsRequested = new();
|
||||
|
||||
public static readonly Subject<string> SetDefaultServerRequested = new();
|
||||
}
|
||||
|
|
|
@ -301,7 +301,7 @@ public class MainWindowViewModel : MyReactiveObject
|
|||
|
||||
private void RefreshSubscriptions()
|
||||
{
|
||||
Locator.Current.GetService<ProfilesViewModel>()?.RefreshSubscriptions();
|
||||
AppEvents.SubscriptionsRefreshRequested.OnNext(Unit.Default);
|
||||
}
|
||||
|
||||
#endregion Servers && Groups
|
||||
|
|
|
@ -240,11 +240,21 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async _ => await RefreshServersBiz());
|
||||
|
||||
AppEvents.SubscriptionsRefreshRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async _ => await RefreshSubscriptions());
|
||||
|
||||
AppEvents.DispatcherStatisticsRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async result => await UpdateStatistics(result));
|
||||
|
||||
AppEvents.SetDefaultServerRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async indexId => await SetDefaultServer(indexId));
|
||||
|
||||
#endregion AppEvents
|
||||
|
||||
_ = Init();
|
||||
|
@ -380,7 +390,7 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null);
|
||||
}
|
||||
|
||||
public async Task RefreshSubscriptions()
|
||||
private async Task RefreshSubscriptions()
|
||||
{
|
||||
SubItems.Clear();
|
||||
|
||||
|
@ -565,7 +575,7 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
await SetDefaultServer(SelectedProfile.IndexId);
|
||||
}
|
||||
|
||||
public async Task SetDefaultServer(string? indexId)
|
||||
private async Task SetDefaultServer(string? indexId)
|
||||
{
|
||||
if (indexId.IsNullOrEmpty())
|
||||
{
|
||||
|
|
|
@ -329,7 +329,7 @@ public class StatusBarViewModel : MyReactiveObject
|
|||
{
|
||||
return;
|
||||
}
|
||||
Locator.Current.GetService<ProfilesViewModel>()?.SetDefaultServer(SelectedServer.ID);
|
||||
AppEvents.SetDefaultServerRequested.OnNext(SelectedServer.ID);
|
||||
}
|
||||
|
||||
public async Task TestServerAvailability()
|
||||
|
|
|
@ -8,7 +8,6 @@ using Avalonia.Threading;
|
|||
using DialogHostAvalonia;
|
||||
using MsBox.Avalonia.Enums;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
using v2rayN.Desktop.Common;
|
||||
|
||||
namespace v2rayN.Desktop.Views;
|
||||
|
@ -48,7 +47,6 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
|
|||
//}
|
||||
|
||||
ViewModel = new ProfilesViewModel(UpdateViewHandler);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(ProfilesViewModel));
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
|
|
|
@ -8,7 +8,6 @@ using System.Windows.Media;
|
|||
using System.Windows.Threading;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
using v2rayN.Base;
|
||||
using Point = System.Windows.Point;
|
||||
|
||||
|
@ -42,7 +41,6 @@ public partial class ProfilesView
|
|||
}
|
||||
|
||||
ViewModel = new ProfilesViewModel(UpdateViewHandler);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(ProfilesViewModel));
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue