fix some bug

This commit is contained in:
Tsuki 2023-04-01 18:57:38 +08:00
parent f1679e444c
commit 5bef6b0492
2 changed files with 64 additions and 28 deletions

View file

@ -138,6 +138,7 @@ namespace v2rayN.Handler
});
}
private readonly object _lock = new object();
private Task RunRealPing()
{
int pid = -1;
@ -174,13 +175,20 @@ namespace v2rayN.Handler
string output = GetRealPingTime(downloadHandle, webProxy);
ProfileExHandler.Instance.SetTestDelay(it.indexId, output);
UpdateFunc(it.indexId, output);
int.TryParse(output, out int delay);
it.delay = delay;
// add a lock to synchronize access to _selecteds list
lock (_lock){
UpdateFunc(it.indexId, output);
int.TryParse(output, out int delay);
it.delay = delay;
}
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
// remove the failed item from the list
lock (_lock){
_selecteds.Remove(it);
}
}
}));
//Thread.Sleep(100);
@ -220,16 +228,21 @@ namespace v2rayN.Handler
DownloadHandle downloadHandle = new();
// add a lock to synchronize access to _selecteds list
lock (_lock){
_selecteds = _selecteds.Where(it => it.allowTest && it.configType != EConfigType.Custom).ToList();
}
foreach (var it in _selecteds)
{
if (!it.allowTest)
{
continue;
}
if (it.configType == EConfigType.Custom)
{
continue;
}
// if (!it.allowTest)
// {
// continue;
// }
// if (it.configType == EConfigType.Custom)
// {
// continue;
// }
//if (it.delay < 0)
//{
// UpdateFunc(it.indexId, "", ResUI.SpeedtestingSkip);
@ -243,15 +256,21 @@ namespace v2rayN.Handler
WebProxy webProxy = new(Global.Loopback, it.port);
await downloadHandle.DownloadDataAsync(url, webProxy, timeout, async (bool success, string msg) =>
{
try{
var msg = await downloadHandle.DownloadDataAsync(url, webProxy, timeout);
decimal.TryParse(msg, out decimal dec);
if (dec > 0)
{
ProfileExHandler.Instance.SetTestSpeed(it.indexId, msg);
}
UpdateFunc(it.indexId, "", msg);
});
}
catch (Exception ex){
Utils.SaveLog(ex.Message, ex);
lock (_lock){
_selecteds.RemoveAll(s => s.indexId == it.indexId);
}
}
}
if (pid > 0)
@ -277,6 +296,8 @@ namespace v2rayN.Handler
DownloadHandle downloadHandle = new();
// add a lock to synchronize access to _selecteds list
var _lock = new object();
foreach (var it in _selecteds)
{
if (!it.allowTest)
@ -294,16 +315,23 @@ namespace v2rayN.Handler
if (item is null) continue;
WebProxy webProxy = new(Global.Loopback, it.port);
_ = downloadHandle.DownloadDataAsync(url, webProxy, timeout, async (bool success, string msg) =>
{
decimal.TryParse(msg, out decimal dec);
if (dec > 0)
{
ProfileExHandler.Instance.SetTestSpeed(it.indexId, msg);
}
UpdateFunc(it.indexId, "", msg);
});
Thread.Sleep(2000);
try{
await downloadHandle.DownloadDataAsync(url, webProxy, timeout, async (bool success, string msg) =>{
decimal.TryParse(msg, out decimal dec);
if (dec > 0)
{
ProfileExHandler.Instance.SetTestSpeed(it.indexId, msg);
}
UpdateFunc(it.indexId, "", msg);
});
}
catch (Exception ex){
// remove the failed item from the list
lock (_lock){
_selecteds.Remove(it);
}
UpdateFunc(it.indexId, "", ResUI.SpeedtestingFailed + ": " + ex.Message);
}
}
Thread.Sleep((timeout + 2) * 1000);

View file

@ -563,8 +563,8 @@ namespace v2rayN.ViewModels
{
return;
}
SpeedProxyDisplay = string.Format("{0}:{1}/s¡ü | {2}/s¡ý", Global.agentTag, Utils.HumanFy(update.proxyUp), Utils.HumanFy(update.proxyDown));
SpeedDirectDisplay = string.Format("{0}:{1}/s¡ü | {2}/s¡ý", Global.directTag, Utils.HumanFy(update.directUp), Utils.HumanFy(update.directDown));
SpeedProxyDisplay = string.Format("{0}:{1}/s<EFBFBD><EFBFBD> | {2}/s<><73>", Global.agentTag, Utils.HumanFy(update.proxyUp), Utils.HumanFy(update.proxyDown));
SpeedDirectDisplay = string.Format("{0}:{1}/s<EFBFBD><EFBFBD> | {2}/s<><73>", Global.directTag, Utils.HumanFy(update.directUp), Utils.HumanFy(update.directDown));
if (update.proxyUp + update.proxyDown > 0)
{
@ -1715,6 +1715,14 @@ namespace v2rayN.ViewModels
public void ModifyTheme(bool isDarkTheme)
{
var theme = _paletteHelper.GetTheme();
//add follow systemTheme
var systemTheme = App.Current.RequestedTheme;
if (systemTheme == AppTheme.Dark){
isDarkTheme = true;
}
else if (systemTheme == AppTheme.Light){
isDarkTheme = false;
}
theme.SetBaseTheme(isDarkTheme ? Theme.Dark : Theme.Light);
_paletteHelper.SetTheme(theme);