mirror of
https://github.com/2dust/v2rayN.git
synced 2026-09-13 18:02:07 +03:00
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>
This commit is contained in:
@@ -5,14 +5,14 @@ public static class ConnectionHandler
|
||||
private static readonly string _tag = "ConnectionHandler";
|
||||
|
||||
/// <summary>
|
||||
/// Runs ping and IP checks and returns a formatted result string.
|
||||
/// Runs ping and IP checks.
|
||||
/// </summary>
|
||||
public static async Task<string> RunAvailabilityCheck()
|
||||
public static async Task<AvailabilityCheckResult> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
6
v2rayN/ServiceLib/Models/Dto/AvailabilityCheckResult.cs
Normal file
6
v2rayN/ServiceLib/Models/Dto/AvailabilityCheckResult.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace ServiceLib.Models.Dto;
|
||||
|
||||
public sealed record AvailabilityCheckResult(int Time, string Ip)
|
||||
{
|
||||
public string? GetValidIp() => Ip == Global.None ? null : Ip;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -324,20 +324,32 @@ public partial class StatusBarViewModel : MyReactiveObject
|
||||
SetDefaultServerRequested.Publish(SelectedServer.ID);
|
||||
}
|
||||
|
||||
public async Task TestServerAvailability()
|
||||
public async Task<AvailabilityCheckResult?> 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)
|
||||
|
||||
Reference in New Issue
Block a user