From 6e35a260e8ff9fa86fef490c51b5160aeeeb9e22 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 26 Oct 2024 09:55:22 +0800 Subject: [PATCH] Bug fix https://github.com/2dust/v2rayN/issues/5915 --- v2rayN/ServiceLib/Handler/ClashApiHandler.cs | 2 +- .../ServiceLib/Handler/CoreConfigHandler.cs | 16 +++---- .../ViewModels/ClashProxiesViewModel.cs | 42 ++++++++++--------- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/ClashApiHandler.cs b/v2rayN/ServiceLib/Handler/ClashApiHandler.cs index dbc98b27..cae3c035 100644 --- a/v2rayN/ServiceLib/Handler/ClashApiHandler.cs +++ b/v2rayN/ServiceLib/Handler/ClashApiHandler.cs @@ -28,7 +28,7 @@ namespace ServiceLib.Handler return new Tuple(clashProxies, clashProviders); } - await Task.Delay(5000); + await Task.Delay(2000); } return null; diff --git a/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs b/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs index cfe05360..84c694c6 100644 --- a/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs @@ -12,18 +12,12 @@ if (node.ConfigType == EConfigType.Custom) { - if (node.CoreType is ECoreType.mihomo) + result = node.CoreType switch { - result = await new CoreConfigClashService(config).GenerateClientCustomConfig(node, fileName); - } - if (node.CoreType is ECoreType.sing_box) - { - result = await new CoreConfigSingboxService(config).GenerateClientCustomConfig(node, fileName); - } - else - { - result = await GenerateClientCustomConfig(node, fileName); - } + ECoreType.mihomo => await new CoreConfigClashService(config).GenerateClientCustomConfig(node, fileName), + ECoreType.sing_box => await new CoreConfigSingboxService(config).GenerateClientCustomConfig(node, fileName), + _ => await GenerateClientCustomConfig(node, fileName) + }; } else if (AppHandler.Instance.GetCoreType(node, node.ConfigType) == ECoreType.sing_box) { diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index 293be335..316e066d 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -96,7 +96,7 @@ namespace ServiceLib.ViewModels private async Task Init() { await ProxiesReload(); - await DelayTestTask(); + DelayTestTask(); } private async Task DoRulemodeSelected(bool c) @@ -434,25 +434,29 @@ namespace ServiceLib.ViewModels public async Task DelayTestTask() { var lastTime = DateTime.Now; + Task.Run(async () => + { + while (true) + { + await Task.Delay(1000 * 60); - Observable.Interval(TimeSpan.FromSeconds(60)) - .Subscribe(async x => - { - if (!(AutoRefresh && _config.UiItem.ShowInTaskbar && _config.IsRunningCore(ECoreType.sing_box))) - { - return; - } - var dtNow = DateTime.Now; - if (_config.ClashUIItem.ProxiesAutoDelayTestInterval > 0) - { - if ((dtNow - lastTime).Minutes % _config.ClashUIItem.ProxiesAutoDelayTestInterval == 0) - { - await ProxiesDelayTest(); - lastTime = dtNow; - } - Task.Delay(1000).Wait(); - } - }); + if (!(AutoRefresh && _config.UiItem.ShowInTaskbar && _config.IsRunningCore(ECoreType.sing_box))) + { + continue; + } + if (_config.ClashUIItem.ProxiesAutoDelayTestInterval <= 0) + { + continue; + } + var dtNow = DateTime.Now; + if ((dtNow - lastTime).Minutes % _config.ClashUIItem.ProxiesAutoDelayTestInterval != 0) + { + continue; + } + await ProxiesDelayTest(); + lastTime = dtNow; + } + }); } #endregion task