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

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

View file

@ -563,8 +563,8 @@ namespace v2rayN.ViewModels
{ {
return; return;
} }
SpeedProxyDisplay = string.Format("{0}:{1}/s¡ü | {2}/s¡ý", Global.agentTag, Utils.HumanFy(update.proxyUp), Utils.HumanFy(update.proxyDown)); 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¡ü | {2}/s¡ý", Global.directTag, Utils.HumanFy(update.directUp), Utils.HumanFy(update.directDown)); 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) if (update.proxyUp + update.proxyDown > 0)
{ {
@ -1715,6 +1715,14 @@ namespace v2rayN.ViewModels
public void ModifyTheme(bool isDarkTheme) public void ModifyTheme(bool isDarkTheme)
{ {
var theme = _paletteHelper.GetTheme(); 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); theme.SetBaseTheme(isDarkTheme ? Theme.Dark : Theme.Light);
_paletteHelper.SetTheme(theme); _paletteHelper.SetTheme(theme);