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 class AppEvents
|
||||||
{
|
{
|
||||||
public static readonly Subject<Unit> ProfilesRefreshRequested = new();
|
public static readonly Subject<Unit> ProfilesRefreshRequested = new();
|
||||||
|
|
||||||
public static readonly Subject<Unit> SubscriptionsRefreshRequested = 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> SendSnackMsgRequested = new();
|
||||||
|
|
||||||
public static readonly Subject<string> SendMsgViewRequested = new();
|
public static readonly Subject<string> SendMsgViewRequested = new();
|
||||||
|
|
||||||
public static readonly Subject<Unit> AppExitRequested = new();
|
public static readonly Subject<Unit> AppExitRequested = new();
|
||||||
|
|
||||||
public static readonly Subject<bool> ShutdownRequested = new();
|
public static readonly Subject<bool> ShutdownRequested = new();
|
||||||
|
|
||||||
public static readonly Subject<Unit> AdjustMainLvColWidthRequested = 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<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 System.Reactive.Concurrency;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using ReactiveUI.Fody.Helpers;
|
using ReactiveUI.Fody.Helpers;
|
||||||
using Splat;
|
|
||||||
|
|
||||||
namespace ServiceLib.ViewModels;
|
namespace ServiceLib.ViewModels;
|
||||||
|
|
||||||
|
@ -240,7 +239,6 @@ public class MainWindowViewModel : MyReactiveObject
|
||||||
BlReloadEnabled = true;
|
BlReloadEnabled = true;
|
||||||
await Reload();
|
await Reload();
|
||||||
await AutoHideStartup();
|
await AutoHideStartup();
|
||||||
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Init
|
#endregion Init
|
||||||
|
@ -433,7 +431,7 @@ public class MainWindowViewModel : MyReactiveObject
|
||||||
var ret = await _updateView?.Invoke(EViewAction.OptionSettingWindow, null);
|
var ret = await _updateView?.Invoke(EViewAction.OptionSettingWindow, null);
|
||||||
if (ret == true)
|
if (ret == true)
|
||||||
{
|
{
|
||||||
Locator.Current.GetService<StatusBarViewModel>()?.InboundDisplayStatus();
|
AppEvents.InboundDisplayRequested.OnNext(Unit.Default);
|
||||||
await Reload();
|
await Reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -444,7 +442,7 @@ public class MainWindowViewModel : MyReactiveObject
|
||||||
if (ret == true)
|
if (ret == true)
|
||||||
{
|
{
|
||||||
await ConfigHandler.InitBuiltinRouting(_config);
|
await ConfigHandler.InitBuiltinRouting(_config);
|
||||||
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
|
AppEvents.RoutingsMenuRefreshRequested.OnNext(Unit.Default);
|
||||||
await Reload();
|
await Reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -518,7 +516,7 @@ public class MainWindowViewModel : MyReactiveObject
|
||||||
await SysProxyHandler.UpdateSysProxy(_config, false);
|
await SysProxyHandler.UpdateSysProxy(_config, false);
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
});
|
});
|
||||||
Locator.Current.GetService<StatusBarViewModel>()?.TestServerAvailability();
|
AppEvents.TestServerRequested.OnNext(Unit.Default);
|
||||||
|
|
||||||
var showClashUI = _config.IsRunningCore(ECoreType.sing_box);
|
var showClashUI = _config.IsRunningCore(ECoreType.sing_box);
|
||||||
if (showClashUI)
|
if (showClashUI)
|
||||||
|
@ -572,7 +570,7 @@ public class MainWindowViewModel : MyReactiveObject
|
||||||
{
|
{
|
||||||
await ConfigHandler.ApplyRegionalPreset(_config, type);
|
await ConfigHandler.ApplyRegionalPreset(_config, type);
|
||||||
await ConfigHandler.InitRouting(_config);
|
await ConfigHandler.InitRouting(_config);
|
||||||
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
|
AppEvents.RoutingsMenuRefreshRequested.OnNext(Unit.Default);
|
||||||
|
|
||||||
await ConfigHandler.SaveConfig(_config);
|
await ConfigHandler.SaveConfig(_config);
|
||||||
await new UpdateService().UpdateGeoFileAll(_config, UpdateTaskHandler);
|
await new UpdateService().UpdateGeoFileAll(_config, UpdateTaskHandler);
|
||||||
|
|
|
@ -209,6 +209,26 @@ public class StatusBarViewModel : MyReactiveObject
|
||||||
.ObserveOn(RxApp.MainThreadScheduler)
|
.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
.Subscribe(async result => await UpdateStatistics(result));
|
.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
|
#endregion AppEvents
|
||||||
|
|
||||||
_ = Init();
|
_ = Init();
|
||||||
|
@ -329,7 +349,7 @@ public class StatusBarViewModel : MyReactiveObject
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AppEvents.SetDefaultServerRequested.OnNext(SelectedServer.ID);
|
AppEvents.SetDefaultServerRequested.OnNext(SelectedServer.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task TestServerAvailability()
|
public async Task TestServerAvailability()
|
||||||
|
@ -364,7 +384,7 @@ public class StatusBarViewModel : MyReactiveObject
|
||||||
|
|
||||||
#region System proxy and Routings
|
#region System proxy and Routings
|
||||||
|
|
||||||
public async Task SetListenerType(ESysProxyType type)
|
private async Task SetListenerType(ESysProxyType type)
|
||||||
{
|
{
|
||||||
if (_config.SystemProxyItem.SysProxyType == type)
|
if (_config.SystemProxyItem.SysProxyType == type)
|
||||||
{
|
{
|
||||||
|
@ -393,7 +413,7 @@ public class StatusBarViewModel : MyReactiveObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RefreshRoutingsMenu()
|
private async Task RefreshRoutingsMenu()
|
||||||
{
|
{
|
||||||
RoutingItems.Clear();
|
RoutingItems.Clear();
|
||||||
|
|
||||||
|
@ -501,7 +521,7 @@ public class StatusBarViewModel : MyReactiveObject
|
||||||
|
|
||||||
#region UI
|
#region UI
|
||||||
|
|
||||||
public async Task InboundDisplayStatus()
|
private async Task InboundDisplayStatus()
|
||||||
{
|
{
|
||||||
StringBuilder sb = new();
|
StringBuilder sb = new();
|
||||||
sb.Append($"[{EInboundProtocol.mixed}:{AppManager.Instance.GetLocalPort(EInboundProtocol.socks)}");
|
sb.Append($"[{EInboundProtocol.mixed}:{AppManager.Instance.GetLocalPort(EInboundProtocol.socks)}");
|
||||||
|
|
|
@ -259,7 +259,7 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
||||||
case EGlobalHotkey.SystemProxySet:
|
case EGlobalHotkey.SystemProxySet:
|
||||||
case EGlobalHotkey.SystemProxyUnchanged:
|
case EGlobalHotkey.SystemProxyUnchanged:
|
||||||
case EGlobalHotkey.SystemProxyPac:
|
case EGlobalHotkey.SystemProxyPac:
|
||||||
Locator.Current.GetService<StatusBarViewModel>()?.SetListenerType((ESysProxyType)((int)e - 1));
|
AppEvents.SysProxyChangeRequested.OnNext((ESysProxyType)((int)e - 1));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,7 +249,7 @@ public partial class MainWindow
|
||||||
case EGlobalHotkey.SystemProxySet:
|
case EGlobalHotkey.SystemProxySet:
|
||||||
case EGlobalHotkey.SystemProxyUnchanged:
|
case EGlobalHotkey.SystemProxyUnchanged:
|
||||||
case EGlobalHotkey.SystemProxyPac:
|
case EGlobalHotkey.SystemProxyPac:
|
||||||
Locator.Current.GetService<StatusBarViewModel>()?.SetListenerType((ESysProxyType)((int)e - 1));
|
AppEvents.SysProxyChangeRequested.OnNext((ESysProxyType)((int)e - 1));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,11 +287,7 @@ public partial class MainWindow
|
||||||
var clipboardData = WindowsUtils.GetClipboardData();
|
var clipboardData = WindowsUtils.GetClipboardData();
|
||||||
if (clipboardData.IsNotEmpty())
|
if (clipboardData.IsNotEmpty())
|
||||||
{
|
{
|
||||||
var service = Locator.Current.GetService<MainWindowViewModel>();
|
ViewModel?.AddServerViaClipboardAsync(clipboardData);
|
||||||
if (service != null)
|
|
||||||
{
|
|
||||||
_ = service.AddServerViaClipboardAsync(clipboardData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -3,7 +3,6 @@ using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using Splat;
|
|
||||||
using v2rayN.Manager;
|
using v2rayN.Manager;
|
||||||
|
|
||||||
namespace v2rayN.Views;
|
namespace v2rayN.Views;
|
||||||
|
@ -17,7 +16,6 @@ public partial class StatusBarView
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_config = AppManager.Instance.Config;
|
_config = AppManager.Instance.Config;
|
||||||
ViewModel = new StatusBarViewModel(UpdateViewHandler);
|
ViewModel = new StatusBarViewModel(UpdateViewHandler);
|
||||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(StatusBarViewModel));
|
|
||||||
|
|
||||||
menuExit.Click += menuExit_Click;
|
menuExit.Click += menuExit_Click;
|
||||||
txtRunningServerDisplay.PreviewMouseDown += txtRunningInfoDisplay_MouseDoubleClick;
|
txtRunningServerDisplay.PreviewMouseDown += txtRunningInfoDisplay_MouseDoubleClick;
|
||||||
|
|
Loading…
Reference in New Issue