mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-26 07:05:00 +03:00
Optimization and improvement, using event subscribers
This commit is contained in:
@@ -6,22 +6,22 @@ namespace ServiceLib.Handler;
|
||||
public static class AppEvents
|
||||
{
|
||||
public static readonly Subject<Unit> ProfilesRefreshRequested = new();
|
||||
|
||||
public static readonly Subject<Unit> SubscriptionsRefreshRequested = new();
|
||||
|
||||
public static readonly Subject<Unit> ProxiesReloadRequested = new();
|
||||
public static readonly Subject<Unit> ProxiesReloadRequested = new();
|
||||
public static readonly Subject<ServerSpeedItem> DispatcherStatisticsRequested = new();
|
||||
|
||||
public static readonly Subject<string> SendSnackMsgRequested = new();
|
||||
|
||||
public static readonly Subject<string> SendMsgViewRequested = new();
|
||||
|
||||
public static readonly Subject<Unit> AppExitRequested = new();
|
||||
|
||||
public static readonly Subject<bool> ShutdownRequested = new();
|
||||
|
||||
public static readonly Subject<Unit> AdjustMainLvColWidthRequested = new();
|
||||
|
||||
public static readonly Subject<ServerSpeedItem> DispatcherStatisticsRequested = new();
|
||||
|
||||
public static readonly Subject<string> SetDefaultServerRequested = new();
|
||||
|
||||
public static readonly Subject<Unit> RoutingsMenuRefreshRequested = new();
|
||||
public static readonly Subject<Unit> TestServerRequested = new();
|
||||
public static readonly Subject<Unit> InboundDisplayRequested = new();
|
||||
public static readonly Subject<ESysProxyType> SysProxyChangeRequested = new();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ using System.Reactive;
|
||||
using System.Reactive.Concurrency;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Splat;
|
||||
|
||||
namespace ServiceLib.ViewModels;
|
||||
|
||||
@@ -240,7 +239,6 @@ public class MainWindowViewModel : MyReactiveObject
|
||||
BlReloadEnabled = true;
|
||||
await Reload();
|
||||
await AutoHideStartup();
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
|
||||
}
|
||||
|
||||
#endregion Init
|
||||
@@ -433,7 +431,7 @@ public class MainWindowViewModel : MyReactiveObject
|
||||
var ret = await _updateView?.Invoke(EViewAction.OptionSettingWindow, null);
|
||||
if (ret == true)
|
||||
{
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.InboundDisplayStatus();
|
||||
AppEvents.InboundDisplayRequested.OnNext(Unit.Default);
|
||||
await Reload();
|
||||
}
|
||||
}
|
||||
@@ -444,7 +442,7 @@ public class MainWindowViewModel : MyReactiveObject
|
||||
if (ret == true)
|
||||
{
|
||||
await ConfigHandler.InitBuiltinRouting(_config);
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
|
||||
AppEvents.RoutingsMenuRefreshRequested.OnNext(Unit.Default);
|
||||
await Reload();
|
||||
}
|
||||
}
|
||||
@@ -518,7 +516,7 @@ public class MainWindowViewModel : MyReactiveObject
|
||||
await SysProxyHandler.UpdateSysProxy(_config, false);
|
||||
await Task.Delay(1000);
|
||||
});
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.TestServerAvailability();
|
||||
AppEvents.TestServerRequested.OnNext(Unit.Default);
|
||||
|
||||
var showClashUI = _config.IsRunningCore(ECoreType.sing_box);
|
||||
if (showClashUI)
|
||||
@@ -572,7 +570,7 @@ public class MainWindowViewModel : MyReactiveObject
|
||||
{
|
||||
await ConfigHandler.ApplyRegionalPreset(_config, type);
|
||||
await ConfigHandler.InitRouting(_config);
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
|
||||
AppEvents.RoutingsMenuRefreshRequested.OnNext(Unit.Default);
|
||||
|
||||
await ConfigHandler.SaveConfig(_config);
|
||||
await new UpdateService().UpdateGeoFileAll(_config, UpdateTaskHandler);
|
||||
|
||||
@@ -209,6 +209,26 @@ public class StatusBarViewModel : MyReactiveObject
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async result => await UpdateStatistics(result));
|
||||
|
||||
AppEvents.RoutingsMenuRefreshRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async _ => await RefreshRoutingsMenu());
|
||||
|
||||
AppEvents.TestServerRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async _ => await TestServerAvailability());
|
||||
|
||||
AppEvents.InboundDisplayRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async _ => await InboundDisplayStatus());
|
||||
|
||||
AppEvents.SysProxyChangeRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async result => await SetListenerType(result));
|
||||
|
||||
#endregion AppEvents
|
||||
|
||||
_ = Init();
|
||||
@@ -329,7 +349,7 @@ public class StatusBarViewModel : MyReactiveObject
|
||||
{
|
||||
return;
|
||||
}
|
||||
AppEvents.SetDefaultServerRequested.OnNext(SelectedServer.ID);
|
||||
AppEvents.SetDefaultServerRequested.OnNext(SelectedServer.ID);
|
||||
}
|
||||
|
||||
public async Task TestServerAvailability()
|
||||
@@ -364,7 +384,7 @@ public class StatusBarViewModel : MyReactiveObject
|
||||
|
||||
#region System proxy and Routings
|
||||
|
||||
public async Task SetListenerType(ESysProxyType type)
|
||||
private async Task SetListenerType(ESysProxyType type)
|
||||
{
|
||||
if (_config.SystemProxyItem.SysProxyType == type)
|
||||
{
|
||||
@@ -393,7 +413,7 @@ public class StatusBarViewModel : MyReactiveObject
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RefreshRoutingsMenu()
|
||||
private async Task RefreshRoutingsMenu()
|
||||
{
|
||||
RoutingItems.Clear();
|
||||
|
||||
@@ -501,7 +521,7 @@ public class StatusBarViewModel : MyReactiveObject
|
||||
|
||||
#region UI
|
||||
|
||||
public async Task InboundDisplayStatus()
|
||||
private async Task InboundDisplayStatus()
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
sb.Append($"[{EInboundProtocol.mixed}:{AppManager.Instance.GetLocalPort(EInboundProtocol.socks)}");
|
||||
|
||||
Reference in New Issue
Block a user