From f03db020faee8100fc053a54e7622a359ef66420 Mon Sep 17 00:00:00 2001 From: Loukky <12481807+Loukky@users.noreply.github.com> Date: Wed, 2 Sep 2026 16:46:15 +0800 Subject: [PATCH] feat: update node IP and delay info on connect (#10050) * feat: update node IP and delay info on connect * Adjust --------- Co-authored-by: 2dust <31833384+2dust@users.noreply.github.com> --- v2rayN/ServiceLib/Handler/ConnectionHandler.cs | 6 +++--- .../Models/Dto/AvailabilityCheckResult.cs | 6 ++++++ .../ViewModels/MainWindowViewModel.cs | 13 ++++++++++++- .../ViewModels/StatusBarViewModel.cs | 18 +++++++++++++++--- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 v2rayN/ServiceLib/Models/Dto/AvailabilityCheckResult.cs diff --git a/v2rayN/ServiceLib/Handler/ConnectionHandler.cs b/v2rayN/ServiceLib/Handler/ConnectionHandler.cs index 80d9d4e7..2cea1e0f 100644 --- a/v2rayN/ServiceLib/Handler/ConnectionHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConnectionHandler.cs @@ -5,14 +5,14 @@ public static class ConnectionHandler private static readonly string _tag = "ConnectionHandler"; /// - /// Runs ping and IP checks and returns a formatted result string. + /// Runs ping and IP checks. /// - public static async Task RunAvailabilityCheck() + public static async Task RunAvailabilityCheck() { var time = await GetRealPingTimeInfo(); var ip = time > 0 ? await GetIPInfo() : Global.None; - return string.Format(ResUI.TestMeOutput, time, ip); + return new AvailabilityCheckResult(time, ip); } /// diff --git a/v2rayN/ServiceLib/Models/Dto/AvailabilityCheckResult.cs b/v2rayN/ServiceLib/Models/Dto/AvailabilityCheckResult.cs new file mode 100644 index 00000000..748b83e0 --- /dev/null +++ b/v2rayN/ServiceLib/Models/Dto/AvailabilityCheckResult.cs @@ -0,0 +1,6 @@ +namespace ServiceLib.Models.Dto; + +public sealed record AvailabilityCheckResult(int Time, string Ip) +{ + public string? GetValidIp() => Ip == Global.None ? null : Ip; +} \ No newline at end of file diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index a6914aa8..e2a3d7ef 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -690,7 +690,18 @@ public partial class MainWindowViewModel : MyReactiveObject }); RxSchedulers.MainThreadScheduler.Schedule(async () => { - await StatusBarViewModel.TestServerAvailability(); + var result = await StatusBarViewModel.TestServerAvailability(); + if (result == null || profileItem.IndexId.IsNullOrEmpty()) + { + return; + } + + await ProfilesViewModel.SetSpeedTestResult(new() + { + IndexId = profileItem.IndexId, + IpInfo = result.Ip, + Delay = result.Time > 0 ? result.Time.ToString() : null + }); }); var showClashUI = AppManager.Instance.IsRunningCore(ECoreType.sing_box); diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index eae93a27..c4983ff7 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -324,20 +324,32 @@ public partial class StatusBarViewModel : MyReactiveObject SetDefaultServerRequested.Publish(SelectedServer.ID); } - public async Task TestServerAvailability() + public async Task TestServerAvailability() { var item = await ConfigHandler.GetDefaultServer(_config); if (item == null) { - return; + return null; } await TestServerAvailabilitySub(ResUI.Speedtesting); - var msg = await Task.Run(ConnectionHandler.RunAvailabilityCheck); + var result = await Task.Run(ConnectionHandler.RunAvailabilityCheck); + var msg = string.Format(ResUI.TestMeOutput, result.Time, result.Ip); + + var ip = result.GetValidIp(); + if (ip.IsNotEmpty()) + { + ProfileExManager.Instance.SetTestIpInfo(item.IndexId, ip); + } + if (result.Time > 0) + { + ProfileExManager.Instance.SetTestDelay(item.IndexId, result.Time); + } NoticeManager.Instance.SendMessageEx(msg); await TestServerAvailabilitySub(msg); + return result; } private async Task TestServerAvailabilitySub(string msg)