mirror of https://github.com/2dust/v2rayN
Optimization and improvement, using event subscribers
parent
6929886b3e
commit
0377e7ce19
|
@ -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<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();
|
||||
|
@ -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)}");
|
||||
|
|
|
@ -259,7 +259,7 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
|||
case EGlobalHotkey.SystemProxySet:
|
||||
case EGlobalHotkey.SystemProxyUnchanged:
|
||||
case EGlobalHotkey.SystemProxyPac:
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.SetListenerType((ESysProxyType)((int)e - 1));
|
||||
AppEvents.SysProxyChangeRequested.OnNext((ESysProxyType)((int)e - 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -249,7 +249,7 @@ public partial class MainWindow
|
|||
case EGlobalHotkey.SystemProxySet:
|
||||
case EGlobalHotkey.SystemProxyUnchanged:
|
||||
case EGlobalHotkey.SystemProxyPac:
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.SetListenerType((ESysProxyType)((int)e - 1));
|
||||
AppEvents.SysProxyChangeRequested.OnNext((ESysProxyType)((int)e - 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -287,11 +287,7 @@ public partial class MainWindow
|
|||
var clipboardData = WindowsUtils.GetClipboardData();
|
||||
if (clipboardData.IsNotEmpty())
|
||||
{
|
||||
var service = Locator.Current.GetService<MainWindowViewModel>();
|
||||
if (service != null)
|
||||
{
|
||||
_ = service.AddServerViaClipboardAsync(clipboardData);
|
||||
}
|
||||
ViewModel?.AddServerViaClipboardAsync(clipboardData);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -3,7 +3,6 @@ using System.Windows;
|
|||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
using v2rayN.Manager;
|
||||
|
||||
namespace v2rayN.Views;
|
||||
|
@ -17,7 +16,6 @@ public partial class StatusBarView
|
|||
InitializeComponent();
|
||||
_config = AppManager.Instance.Config;
|
||||
ViewModel = new StatusBarViewModel(UpdateViewHandler);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(StatusBarViewModel));
|
||||
|
||||
menuExit.Click += menuExit_Click;
|
||||
txtRunningServerDisplay.PreviewMouseDown += txtRunningInfoDisplay_MouseDoubleClick;
|
||||
|
|
Loading…
Reference in New Issue