diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index a8160c7f..fc3d6f23 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -582,7 +582,7 @@ namespace ServiceLib.ViewModels } else { - SetDefaultServer(indexId); + await SetDefaultServer(indexId); } } diff --git a/v2rayN/v2rayN.Desktop/App.axaml b/v2rayN/v2rayN.Desktop/App.axaml index edfa18e6..d8503ed2 100644 --- a/v2rayN/v2rayN.Desktop/App.axaml +++ b/v2rayN/v2rayN.Desktop/App.axaml @@ -33,6 +33,10 @@ ToolTipText="v2rayN Desktop"> + + + + diff --git a/v2rayN/v2rayN.Desktop/ViewModels/AppViewModel.cs b/v2rayN/v2rayN.Desktop/ViewModels/AppViewModel.cs index c7726c25..db9e11f5 100644 --- a/v2rayN/v2rayN.Desktop/ViewModels/AppViewModel.cs +++ b/v2rayN/v2rayN.Desktop/ViewModels/AppViewModel.cs @@ -9,6 +9,9 @@ namespace v2rayN.Desktop.ViewModels { public class AppViewModel : MyReactiveObject { + public ReactiveCommand SystemProxyClearCmd { get; } + public ReactiveCommand SystemProxySetCmd { get; } + public ReactiveCommand SystemProxyNothingCmd { get; } public ReactiveCommand AddServerViaClipboardCmd { get; } public ReactiveCommand SubUpdateCmd { get; } public ReactiveCommand SubUpdateViaProxyCmd { get; } @@ -18,33 +21,78 @@ namespace v2rayN.Desktop.ViewModels { _config = AppHandler.Instance.Config; - AddServerViaClipboardCmd = ReactiveCommand.Create(() => + SystemProxyClearCmd = ReactiveCommand.CreateFromTask(async () => { - if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + await SetListenerType(ESysProxyType.ForcedClear); + }); + SystemProxySetCmd = ReactiveCommand.CreateFromTask(async () => + { + await SetListenerType(ESysProxyType.ForcedChange); + }); + SystemProxyNothingCmd = ReactiveCommand.CreateFromTask(async () => + { + await SetListenerType(ESysProxyType.Unchanged); + }); + + AddServerViaClipboardCmd = ReactiveCommand.CreateFromTask(async () => + { + await AddServerViaClipboard(); + }); + + SubUpdateCmd = ReactiveCommand.CreateFromTask(async () => + { + await UpdateSubscriptionProcess(false); + }); + SubUpdateViaProxyCmd = ReactiveCommand.CreateFromTask(async () => + { + await UpdateSubscriptionProcess(true); + }); + + ExitCmd = ReactiveCommand.CreateFromTask(async () => + { + await Exit(); + }); + } + + private async Task SetListenerType(ESysProxyType type) + { + if (_config.systemProxyItem.sysProxyType == type) + { + return; + } + + var service = Locator.Current.GetService(); + if (service != null) await service.SetListenerType(type); + } + + private async Task AddServerViaClipboard() + { + if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + if (desktop.MainWindow != null) { - var clipboardData = AvaUtils.GetClipboardData(desktop.MainWindow).Result; - Locator.Current.GetService()?.AddServerViaClipboardAsync(clipboardData); + var clipboardData = await AvaUtils.GetClipboardData(desktop.MainWindow); + var service = Locator.Current.GetService(); + if (service != null) await service.AddServerViaClipboardAsync(clipboardData); } - }); + } + } - SubUpdateCmd = ReactiveCommand.Create(() => - { - Locator.Current.GetService()?.UpdateSubscriptionProcess("", false); - }); - SubUpdateViaProxyCmd = ReactiveCommand.Create(() => - { - Locator.Current.GetService()?.UpdateSubscriptionProcess("", true); - }); + private async Task UpdateSubscriptionProcess(bool blProxy) + { + var service = Locator.Current.GetService(); + if (service != null) await service.UpdateSubscriptionProcess("", blProxy); + } - ExitCmd = ReactiveCommand.Create(() => + private async Task Exit() + { + if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) - { - Locator.Current.GetService()?.MyAppExitAsync(false); + var service = Locator.Current.GetService(); + if (service != null) await service.MyAppExitAsync(false); - desktop.Shutdown(); - } - }); + desktop.Shutdown(); + } } } } \ No newline at end of file diff --git a/v2rayN/v2rayN.Desktop/Views/RoutingSettingWindow.axaml b/v2rayN/v2rayN.Desktop/Views/RoutingSettingWindow.axaml index b864c639..90dbf965 100644 --- a/v2rayN/v2rayN.Desktop/Views/RoutingSettingWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/RoutingSettingWindow.axaml @@ -92,6 +92,9 @@ HeadersVisibility="Column" IsReadOnly="True" ItemsSource="{Binding RoutingItems}"> + + + diff --git a/v2rayN/v2rayN.Desktop/Views/RoutingSettingWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/RoutingSettingWindow.axaml.cs index 76fbac61..159eb4e2 100644 --- a/v2rayN/v2rayN.Desktop/Views/RoutingSettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/RoutingSettingWindow.axaml.cs @@ -82,12 +82,7 @@ namespace v2rayN.Desktop.Views } private void RoutingSettingWindow_KeyDown(object? sender, KeyEventArgs e) - { - if (ViewModel?.enableRoutingBasic ?? false) - { - return; - } - + { if (e.KeyModifiers == KeyModifiers.Control) { if (e.Key == Key.A)