Compare commits

...

9 commits

Author SHA1 Message Date
fonaix
224677eb8f
Merge e45c1ddb36 into 8aceff7480 2024-12-05 15:22:30 +08:00
2dust
8aceff7480 Enhanced testing function
Separate xray-core and sing-box-core testing
2024-12-05 15:21:16 +08:00
2dust
736c450161 Improve the code 2024-12-05 14:05:12 +08:00
2dust
3b63a3d308 Fix
https://github.com/2dust/v2rayN/issues/6216
2024-12-05 14:04:39 +08:00
2dust
4f56174c8f Bug fix
https://github.com/2dust/v2rayN/issues/6219
2024-12-05 12:16:53 +08:00
fonaix
e45c1ddb36
Merge branch '2dust:master' into master 2024-12-05 08:31:48 +08:00
fonaix
893c04b3b7
Merge branch '2dust:master' into master 2024-12-03 08:43:21 +08:00
fonaix
d8b0363bb7
Merge branch '2dust:master' into master 2024-12-01 14:50:18 +08:00
fonaix
e3a90442a9 修复:后台启动时,闪一下的问题 2024-12-01 04:13:09 +08:00
7 changed files with 105 additions and 82 deletions

View file

@ -1029,12 +1029,11 @@ namespace ServiceLib.Handler
public static async Task<ProfileItem?> GetPreSocksItem(Config config, ProfileItem node, ECoreType coreType)
{
ProfileItem? itemSocks = null;
var preCoreType = ECoreType.sing_box;
if (node.ConfigType != EConfigType.Custom && coreType != ECoreType.sing_box && config.TunModeItem.EnableTun)
{
itemSocks = new ProfileItem()
{
CoreType = preCoreType,
CoreType = ECoreType.sing_box,
ConfigType = EConfigType.SOCKS,
Address = Global.Loopback,
Sni = node.Address, //Tun2SocksAddress
@ -1043,7 +1042,7 @@ namespace ServiceLib.Handler
}
else if ((node.ConfigType == EConfigType.Custom && node.PreSocksPort > 0))
{
preCoreType = config.TunModeItem.EnableTun ? ECoreType.sing_box : ECoreType.Xray;
var preCoreType = config.RunningCoreType = config.TunModeItem.EnableTun ? ECoreType.sing_box : ECoreType.Xray;
itemSocks = new ProfileItem()
{
CoreType = preCoreType,

View file

@ -174,7 +174,7 @@ namespace ServiceLib.Handler
var itemSocks = await ConfigHandler.GetPreSocksItem(_config, node, coreType);
if (itemSocks != null)
{
var preCoreType = _config.RunningCoreType = itemSocks.CoreType ?? ECoreType.sing_box;
var preCoreType = itemSocks.CoreType ?? ECoreType.sing_box;
var fileName = Utils.GetConfigPath(Global.CorePreConfigFileName);
var result = await CoreConfigHandler.GenerateClientConfig(itemSocks, fileName);
if (result.Success)

View file

@ -349,20 +349,20 @@ namespace ServiceLib.Models
public string? path { get; set; }
public string? host { get; set; }
public string? mode { get; set; }
public string? scMaxEachPostBytes { get; set; }
public string? scMaxConcurrentPosts { get; set; }
public string? scMinPostsIntervalMs { get; set; }
public Xmux4Ray? xmux { get; set; }
public object? scMaxEachPostBytes { get; set; }
public object? scMaxConcurrentPosts { get; set; }
public object? scMinPostsIntervalMs { get; set; }
//public Xmux4Ray? xmux { get; set; }
public object? extra { get; set; }
}
public class Xmux4Ray
{
public int? maxConcurrency { get; set; }
public int? maxConnections { get; set; }
public int? cMaxReuseTimes { get; set; }
public int? cMaxLifetimeMs { get; set; }
}
//public class Xmux4Ray
//{
// public object? maxConcurrency { get; set; }
// public object? maxConnections { get; set; }
// public object? cMaxReuseTimes { get; set; }
// public object? cMaxLifetimeMs { get; set; }
//}
public class HttpSettings4Ray
{

View file

@ -8,19 +8,16 @@ namespace ServiceLib.Services
public class SpeedtestService
{
private Config? _config;
private List<ServerTestItem> _selecteds;
private ESpeedActionType _actionType;
private Action<SpeedTestResult>? _updateFunc;
private bool _exitLoop = false;
public SpeedtestService(Config config, List<ProfileItem> selecteds, ESpeedActionType actionType, Action<SpeedTestResult> updateFunc)
{
_config = config;
_actionType = actionType;
_updateFunc = updateFunc;
_selecteds = new List<ServerTestItem>();
var lstSelected = new List<ServerTestItem>();
foreach (var it in selecteds)
{
if (it.ConfigType == EConfigType.Custom)
@ -31,7 +28,7 @@ namespace ServiceLib.Services
{
continue;
}
_selecteds.Add(new ServerTestItem()
lstSelected.Add(new ServerTestItem()
{
IndexId = it.IndexId,
Address = it.Address,
@ -39,8 +36,9 @@ namespace ServiceLib.Services
ConfigType = it.ConfigType
});
}
//clear test result
foreach (var it in _selecteds)
foreach (var it in lstSelected)
{
switch (actionType)
{
@ -63,25 +61,44 @@ namespace ServiceLib.Services
}
}
MessageBus.Current.Listen<string>(EMsgCommand.StopSpeedtest.ToString()).Subscribe(ExitLoop);
Task.Run(async () => { await RunAsync(actionType, lstSelected); });
}
private async Task RunAsync(ESpeedActionType actionType, List<ServerTestItem> lstSelected)
{
if (actionType == ESpeedActionType.Tcping)
{
await RunTcpingAsync(lstSelected);
return;
}
List<List<ServerTestItem>> lstTest = new();
lstTest.Add(lstSelected.Where(t => t.ConfigType is not (EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.WireGuard)).ToList());
lstTest.Add(lstSelected.Where(t => t.ConfigType is EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.WireGuard).ToList());
foreach (var lst in lstTest)
{
switch (actionType)
{
case ESpeedActionType.Tcping:
Task.Run(RunTcping);
break;
case ESpeedActionType.Realping:
Task.Run(RunRealPing);
await RunRealPingAsync(lst);
break;
case ESpeedActionType.Speedtest:
Task.Run(RunSpeedTestAsync);
await RunSpeedTestAsync(lst);
break;
case ESpeedActionType.Mixedtest:
Task.Run(RunMixedtestAsync);
await RunMixedTestAsync(lst);
break;
}
MessageBus.Current.Listen<string>(EMsgCommand.StopSpeedtest.ToString()).Subscribe(ExitLoop);
await Task.Delay(1000);
}
UpdateFunc("", ResUI.SpeedtestingCompleted);
}
private void ExitLoop(string x)
@ -91,12 +108,12 @@ namespace ServiceLib.Services
UpdateFunc("", ResUI.SpeedtestingStop);
}
private async Task RunTcping()
private async Task RunTcpingAsync(List<ServerTestItem> selecteds)
{
try
{
List<Task> tasks = [];
foreach (var it in _selecteds)
foreach (var it in selecteds)
{
if (it.ConfigType == EConfigType.Custom)
{
@ -106,7 +123,7 @@ namespace ServiceLib.Services
{
try
{
int time = await GetTcpingTime(it.Address, it.Port);
var time = await GetTcpingTime(it.Address, it.Port);
var output = FormatOut(time, Global.DelayUnit);
ProfileExHandler.Instance.SetTestDelay(it.IndexId, output);
@ -130,24 +147,22 @@ namespace ServiceLib.Services
}
}
private async Task RunRealPing()
private async Task RunRealPingAsync(List<ServerTestItem> selecteds)
{
int pid = -1;
var pid = -1;
try
{
string msg = string.Empty;
pid = await CoreHandler.Instance.LoadCoreConfigSpeedtest(_selecteds);
pid = await CoreHandler.Instance.LoadCoreConfigSpeedtest(selecteds);
if (pid < 0)
{
UpdateFunc("", ResUI.FailedToRunCore);
return;
}
DownloadService downloadHandle = new DownloadService();
var downloadHandle = new DownloadService();
List<Task> tasks = new();
foreach (var it in _selecteds)
foreach (var it in selecteds)
{
if (!it.AllowTest)
{
@ -162,11 +177,11 @@ namespace ServiceLib.Services
try
{
WebProxy webProxy = new(Global.Loopback, it.Port);
string output = await GetRealPingTime(downloadHandle, webProxy);
var output = await GetRealPingTime(downloadHandle, webProxy);
ProfileExHandler.Instance.SetTestDelay(it.IndexId, output);
UpdateFunc(it.IndexId, output);
int.TryParse(output, out int delay);
int.TryParse(output, out var delay);
it.Delay = delay;
}
catch (Exception ex)
@ -191,27 +206,22 @@ namespace ServiceLib.Services
}
}
private async Task RunSpeedTestAsync()
private async Task RunSpeedTestAsync(List<ServerTestItem> selecteds)
{
int pid = -1;
//if (_actionType == ESpeedActionType.Mixedtest)
//{
// _selecteds = _selecteds.OrderBy(t => t.delay).ToList();
//}
pid = await CoreHandler.Instance.LoadCoreConfigSpeedtest(_selecteds);
var pid = -1;
pid = await CoreHandler.Instance.LoadCoreConfigSpeedtest(selecteds);
if (pid < 0)
{
UpdateFunc("", ResUI.FailedToRunCore);
return;
}
string url = _config.SpeedTestItem.SpeedTestUrl;
var url = _config.SpeedTestItem.SpeedTestUrl;
var timeout = _config.SpeedTestItem.SpeedTestTimeout;
DownloadService downloadHandle = new();
foreach (var it in _selecteds)
foreach (var it in selecteds)
{
if (_exitLoop)
{
@ -241,7 +251,7 @@ namespace ServiceLib.Services
await downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
{
decimal.TryParse(msg, out decimal dec);
decimal.TryParse(msg, out var dec);
if (dec > 0)
{
ProfileExHandler.Instance.SetTestSpeed(it.IndexId, msg);
@ -254,26 +264,25 @@ namespace ServiceLib.Services
{
await CoreHandler.Instance.CoreStopPid(pid);
}
UpdateFunc("", ResUI.SpeedtestingCompleted);
await ProfileExHandler.Instance.SaveTo();
}
private async Task RunSpeedTestMulti()
private async Task RunSpeedTestMulti(List<ServerTestItem> selecteds)
{
int pid = -1;
pid = await CoreHandler.Instance.LoadCoreConfigSpeedtest(_selecteds);
var pid = -1;
pid = await CoreHandler.Instance.LoadCoreConfigSpeedtest(selecteds);
if (pid < 0)
{
UpdateFunc("", ResUI.FailedToRunCore);
return;
}
string url = _config.SpeedTestItem.SpeedTestUrl;
var url = _config.SpeedTestItem.SpeedTestUrl;
var timeout = _config.SpeedTestItem.SpeedTestTimeout;
DownloadService downloadHandle = new();
foreach (var it in _selecteds)
foreach (var it in selecteds)
{
if (_exitLoop)
{
@ -303,7 +312,7 @@ namespace ServiceLib.Services
WebProxy webProxy = new(Global.Loopback, it.Port);
_ = downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
{
decimal.TryParse(msg, out decimal dec);
decimal.TryParse(msg, out var dec);
if (dec > 0)
{
ProfileExHandler.Instance.SetTestSpeed(it.IndexId, msg);
@ -319,35 +328,34 @@ namespace ServiceLib.Services
{
await CoreHandler.Instance.CoreStopPid(pid);
}
UpdateFunc("", ResUI.SpeedtestingCompleted);
await ProfileExHandler.Instance.SaveTo();
}
private async Task RunMixedtestAsync()
private async Task RunMixedTestAsync(List<ServerTestItem> selecteds)
{
await RunRealPing();
await RunRealPingAsync(selecteds);
await Task.Delay(1000);
await RunSpeedTestMulti();
await RunSpeedTestMulti(selecteds);
}
private async Task<string> GetRealPingTime(DownloadService downloadHandle, IWebProxy webProxy)
{
int responseTime = await downloadHandle.GetRealPingTime(_config.SpeedTestItem.SpeedPingTestUrl, webProxy, 10);
var responseTime = await downloadHandle.GetRealPingTime(_config.SpeedTestItem.SpeedPingTestUrl, webProxy, 10);
//string output = Utile.IsNullOrEmpty(status) ? FormatOut(responseTime, "ms") : status;
return FormatOut(responseTime, Global.DelayUnit);
}
private async Task<int> GetTcpingTime(string url, int port)
{
int responseTime = -1;
var responseTime = -1;
try
{
if (!IPAddress.TryParse(url, out IPAddress? ipAddress))
if (!IPAddress.TryParse(url, out var ipAddress))
{
IPHostEntry ipHostInfo = Dns.GetHostEntry(url);
var ipHostInfo = await Dns.GetHostEntryAsync(url);
ipAddress = ipHostInfo.AddressList.First();
}

View file

@ -31,9 +31,17 @@ public partial class App : Application
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
AppHandler.Instance.InitComponents();
desktop.ShutdownMode = Avalonia.Controls.ShutdownMode.OnExplicitShutdown;
desktop.Exit += OnExit;
desktop.MainWindow = new MainWindow();
var mainWindow = new MainWindow();
if (!AppHandler.Instance.Config.UiItem.AutoHideStartup)
{
desktop.MainWindow = mainWindow;
}
else
{
desktop.MainWindow = null;
}
}
base.OnFrameworkInitializationCompleted();

View file

@ -396,6 +396,10 @@ namespace v2rayN.Desktop.Views
if (bl)
{
this.Show();
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = this;
}
if (this.WindowState == WindowState.Minimized)
{
this.WindowState = WindowState.Normal;

View file

@ -77,9 +77,13 @@ namespace v2rayN.Desktop.Views
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow.Icon = AvaUtils.GetAppIcon(_config.SystemProxyItem.SysProxyType);
var icon = AvaUtils.GetAppIcon(_config.SystemProxyItem.SysProxyType);
if (desktop.MainWindow != null)
{
desktop.MainWindow.Icon = icon;
}
var iconslist = TrayIcon.GetIcons(Application.Current);
iconslist[0].Icon = desktop.MainWindow.Icon;
iconslist[0].Icon = icon;
TrayIcon.SetIcons(Application.Current, iconslist);
}
}