From 67ffa810d300c803edcb1b8d40775324500fd12e Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:28:51 +0800 Subject: [PATCH] Optimize code and remove Action --- v2rayN/ServiceLib/Services/UpdateService.cs | 4 ++-- v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index 2d086a22553..428a136b61b 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -243,7 +243,7 @@ public async Task UpdateGeoFileAll(Config config, Action updateFun _updateFunc?.Invoke(true, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, "geo")); } - public async Task RunAvailabilityCheck(Action updateFunc) + public async Task RunAvailabilityCheck() { var downloadHandle = new DownloadService(); var time = await downloadHandle.RunAvailabilityCheck(null); @@ -255,7 +255,7 @@ public async Task RunAvailabilityCheck(Action updateFunc) ip = $"({ipInfo?.country_code}) {ipInfo?.ip}"; } - updateFunc?.Invoke(false, string.Format(ResUI.TestMeOutput, time, ip)); + return string.Format(ResUI.TestMeOutput, time, ip); } #region CheckUpdate private diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index cb49682e133..efff619569f 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -311,11 +311,11 @@ public async Task TestServerAvailability() { return; } - await (new UpdateService()).RunAvailabilityCheck(async (bool success, string msg) => - { - NoticeHandler.Instance.SendMessageEx(msg); - _updateView?.Invoke(EViewAction.DispatcherServerAvailability, msg); - }); + + var msg = await (new UpdateService()).RunAvailabilityCheck(); + + NoticeHandler.Instance.SendMessageEx(msg); + _updateView?.Invoke(EViewAction.DispatcherServerAvailability, msg); } public void TestServerAvailabilityResult(string msg)