From 5867c51a03e2648b3544b6be1c927ade069afcf9 Mon Sep 17 00:00:00 2001 From: sshcomm <sadeqgsm96@gmail.com> Date: Wed, 29 Jan 2025 23:24:19 +0330 Subject: [PATCH] Update TaskHandler.cs --- v2rayN/ServiceLib/Handler/TaskHandler.cs | 70 +++++++++++++++++++++++- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/TaskHandler.cs b/v2rayN/ServiceLib/Handler/TaskHandler.cs index 3d04a33d..b7b8dc94 100644 --- a/v2rayN/ServiceLib/Handler/TaskHandler.cs +++ b/v2rayN/ServiceLib/Handler/TaskHandler.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Handler +namespace ServiceLib.Handler { public class TaskHandler { @@ -9,6 +9,8 @@ { Task.Run(() => UpdateTaskRunSubscription(config, updateFunc)); Task.Run(() => UpdateTaskRunGeo(config, updateFunc)); + Task.Run(() => UpdateTaskRunCore(config, updateFunc)); + Task.Run(() => UpdateTaskRunGui(config, updateFunc)); } private async Task UpdateTaskRunSubscription(Config config, Action<bool, string> updateFunc) @@ -46,7 +48,6 @@ { var autoUpdateGeoTime = DateTime.Now; - //await Task.Delay(1000 * 120); Logging.SaveLog("UpdateTaskRunGeo"); var updateHandle = new UpdateService(); @@ -68,5 +69,68 @@ } } } + + private async Task UpdateTaskRunCore(Config config, Action<bool, string> updateFunc) + { + var autoUpdateCoreTime = DateTime.Now; + + Logging.SaveLog("UpdateTaskRunCore"); + + var updateHandle = new UpdateService(); + while (true) + { + await Task.Delay(1000 * 3600); + + var dtNow = DateTime.Now; + if (config.GuiItem.AutoUpdateCoreInterval > 0) + { + if ((dtNow - autoUpdateCoreTime).Hours % config.GuiItem.AutoUpdateCoreInterval == 0) + { + await updateHandle.CheckUpdateCore(ECoreType.Xray, config, (bool success, string msg) => + { + updateFunc?.Invoke(success, msg); + }, false); + + await updateHandle.CheckUpdateCore(ECoreType.sing_box, config, (bool success, string msg) => + { + updateFunc?.Invoke(success, msg); + }, false); + + await updateHandle.CheckUpdateCore(ECoreType.mihomo, config, (bool success, string msg) => + { + updateFunc?.Invoke(success, msg); + }, false); + + autoUpdateCoreTime = dtNow; + } + } + } + } + + private async Task UpdateTaskRunGui(Config config, Action<bool, string> updateFunc) + { + var autoUpdateGuiTime = DateTime.Now; + + Logging.SaveLog("UpdateTaskRunGui"); + + var updateHandle = new UpdateService(); + while (true) + { + await Task.Delay(1000 * 3600); + + var dtNow = DateTime.Now; + if (config.GuiItem.AutoUpdateCoreInterval > 0) + { + if ((dtNow - autoUpdateGuiTime).Hours % config.GuiItem.AutoUpdateCoreInterval == 0) + { + await updateHandle.CheckUpdateGuiN(config, (bool success, string msg) => + { + updateFunc?.Invoke(success, msg); + }, false); + autoUpdateGuiTime = dtNow; + } + } + } + } } -} \ No newline at end of file +}