diff --git a/v2rayN/ServiceLib/Handler/ClashApiHandler.cs b/v2rayN/ServiceLib/Handler/ClashApiHandler.cs index 7ba04885..01134e6d 100644 --- a/v2rayN/ServiceLib/Handler/ClashApiHandler.cs +++ b/v2rayN/ServiceLib/Handler/ClashApiHandler.cs @@ -7,9 +7,9 @@ namespace ServiceLib.Handler private static readonly Lazy instance = new(() => new()); public static ClashApiHandler Instance => instance.Value; + private static readonly string _tag = "ClashApiHandler"; private Dictionary? _proxies; public Dictionary ProfileContent { get; set; } - private static readonly string _tag = "ClashApiHandler"; public async Task?> GetClashProxiesAsync(Config config) { @@ -54,7 +54,7 @@ namespace ServiceLib.Handler return; } lstProxy = new List(); - foreach (KeyValuePair kv in _proxies) + foreach (var kv in _proxies) { if (Global.notAllowTestType.Contains(kv.Value.type.ToLower())) { diff --git a/v2rayN/ServiceLib/Handler/TaskHandler.cs b/v2rayN/ServiceLib/Handler/TaskHandler.cs index 88657f0c..08c01a46 100644 --- a/v2rayN/ServiceLib/Handler/TaskHandler.cs +++ b/v2rayN/ServiceLib/Handler/TaskHandler.cs @@ -26,7 +26,7 @@ namespace ServiceLib.Handler //Execute once 20 minute if (numOfExecuted % 20 == 0) { - Logging.SaveLog("Execute save config"); + //Logging.SaveLog("Execute save config"); await ConfigHandler.SaveConfig(config); await ProfileExHandler.Instance.SaveTo(); @@ -35,7 +35,7 @@ namespace ServiceLib.Handler //Execute once 1 hour if (numOfExecuted % 60 == 0) { - Logging.SaveLog("Execute delete expired files"); + //Logging.SaveLog("Execute delete expired files"); FileManager.DeleteExpiredFiles(Utils.GetBinConfigPath(), DateTime.Now.AddHours(-1)); FileManager.DeleteExpiredFiles(Utils.GetLogPath(), DateTime.Now.AddMonths(-1)); @@ -72,7 +72,7 @@ namespace ServiceLib.Handler updateFunc?.Invoke(success, msg); if (success) { - Logging.SaveLog("Update subscription end" + msg); + Logging.SaveLog($"Update subscription end. {msg}"); } }); item.UpdateTime = updateTime; diff --git a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs index 761fd9b7..166da0ee 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs @@ -53,26 +53,31 @@ namespace ServiceLib.ViewModels private async Task Init() { - var lastTime = DateTime.Now; + Task.Run(async () => + { + var numOfExecuted = 1; + while (true) + { + await Task.Delay(1000 * 5); + numOfExecuted++; + if (!(AutoRefresh && _config.UiItem.ShowInTaskbar && _config.IsRunningCore(ECoreType.sing_box))) + { + continue; + } + + if (_config.ClashUIItem.ConnectionsRefreshInterval <= 0) + { + continue; + } + + if (numOfExecuted % _config.ClashUIItem.ConnectionsRefreshInterval != 0) + { + continue; + } + await GetClashConnections(); + } + }); - Observable.Interval(TimeSpan.FromSeconds(5)) - .Subscribe(async x => - { - if (!(AutoRefresh && _config.UiItem.ShowInTaskbar && _config.IsRunningCore(ECoreType.sing_box))) - { - return; - } - var dtNow = DateTime.Now; - if (_config.ClashUIItem.ConnectionsRefreshInterval > 0) - { - if ((dtNow - lastTime).Minutes % _config.ClashUIItem.ConnectionsRefreshInterval == 0) - { - await GetClashConnections(); - lastTime = dtNow; - } - Task.Delay(1000).Wait(); - } - }); await Task.CompletedTask; } diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index 091a4215..5d8535c4 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -95,8 +95,8 @@ namespace ServiceLib.ViewModels private async Task Init() { - await ProxiesReload(); _ = DelayTestTask(); + await ProxiesReload(); } private async Task DoRulemodeSelected(bool c) @@ -383,8 +383,6 @@ namespace ServiceLib.ViewModels private async Task ProxiesDelayTest(bool blAll) { - //UpdateHandler(false, "Clash Proxies Latency Test"); - ClashApiHandler.Instance.ClashProxiesDelayTest(blAll, _proxyDetails.ToList(), async (item, result) => { if (item == null) @@ -434,13 +432,13 @@ namespace ServiceLib.ViewModels public async Task DelayTestTask() { - var lastTime = DateTime.Now; - _ = Task.Run(async () => + Task.Run(async () => { + var numOfExecuted = 1; while (true) { await Task.Delay(1000 * 60); - + numOfExecuted++; if (!(AutoRefresh && _config.UiItem.ShowInTaskbar && _config.IsRunningCore(ECoreType.sing_box))) { continue; @@ -449,13 +447,11 @@ namespace ServiceLib.ViewModels { continue; } - var dtNow = DateTime.Now; - if ((dtNow - lastTime).Minutes % _config.ClashUIItem.ProxiesAutoDelayTestInterval != 0) + if (numOfExecuted % _config.ClashUIItem.ProxiesAutoDelayTestInterval != 0) { continue; } await ProxiesDelayTest(); - lastTime = dtNow; } }); await Task.CompletedTask;