mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-31 17:45:00 +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";
|
private static readonly string _tag = "ConnectionHandler";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Runs ping and IP checks and returns a formatted result string.
|
/// Runs ping and IP checks.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static async Task<string> RunAvailabilityCheck()
|
public static async Task<AvailabilityCheckResult> RunAvailabilityCheck()
|
||||||
{
|
{
|
||||||
var time = await GetRealPingTimeInfo();
|
var time = await GetRealPingTimeInfo();
|
||||||
var ip = time > 0 ? await GetIPInfo() : Global.None;
|
var ip = time > 0 ? await GetIPInfo() : Global.None;
|
||||||
|
|
||||||
return string.Format(ResUI.TestMeOutput, time, ip);
|
return new AvailabilityCheckResult(time, ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -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 () =>
|
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);
|
var showClashUI = AppManager.Instance.IsRunningCore(ECoreType.sing_box);
|
||||||
|
|||||||
@@ -324,20 +324,32 @@ public partial class StatusBarViewModel : MyReactiveObject
|
|||||||
SetDefaultServerRequested.Publish(SelectedServer.ID);
|
SetDefaultServerRequested.Publish(SelectedServer.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task TestServerAvailability()
|
public async Task<AvailabilityCheckResult?> TestServerAvailability()
|
||||||
{
|
{
|
||||||
var item = await ConfigHandler.GetDefaultServer(_config);
|
var item = await ConfigHandler.GetDefaultServer(_config);
|
||||||
if (item == null)
|
if (item == null)
|
||||||
{
|
{
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
await TestServerAvailabilitySub(ResUI.Speedtesting);
|
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);
|
NoticeManager.Instance.SendMessageEx(msg);
|
||||||
await TestServerAvailabilitySub(msg);
|
await TestServerAvailabilitySub(msg);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TestServerAvailabilitySub(string msg)
|
private async Task TestServerAvailabilitySub(string msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user