Optimize speedtest (#8325)

* Optimize stop-speedtest tip display

* Fix speedtest termination latency
This commit is contained in:
Harry Huang
2025-11-16 14:58:55 +08:00
committed by GitHub
parent 4fb41aeca1
commit 8ea5a57988
9 changed files with 75 additions and 23 deletions

View File

@@ -2355,6 +2355,15 @@ namespace ServiceLib.Resx {
}
}
/// <summary>
/// 查找类似 Press ESC to terminate the test 的本地化字符串。
/// </summary>
public static string SpeedtestingPressEscToExit {
get {
return ResourceManager.GetString("SpeedtestingPressEscToExit", resourceCulture);
}
}
/// <summary>
/// 查找类似 Skip test 的本地化字符串。
/// </summary>
@@ -2383,7 +2392,7 @@ namespace ServiceLib.Resx {
}
/// <summary>
/// 查找类似 Waiting for testing (press ESC to terminate)... 的本地化字符串。
/// 查找类似 Waiting... 的本地化字符串。
/// </summary>
public static string SpeedtestingWait {
get {

View File

@@ -976,7 +976,10 @@
<value>فعال‌ سازی شتاب‌ دهنده سخت‌ افزاری (نیاز به راه‌اندازی مجدد)</value>
</data>
<data name="SpeedtestingWait" xml:space="preserve">
<value>در انتظار آزمایش (برای پایان دادن به ESC فشار دهید)...</value>
<value>در انتظار آزمایش...</value>
</data>
<data name="SpeedtestingPressEscToExit" xml:space="preserve">
<value>برای پایان دادن به ESC فشار دهید</value>
</data>
<data name="TipDisplayLog" xml:space="preserve">
<value>لطفاً در صورت قطع غیرعادی آن را خاموش کنید</value>

View File

@@ -976,7 +976,10 @@
<value>Activer laccélération matérielle (redémarrage requis)</value>
</data>
<data name="SpeedtestingWait" xml:space="preserve">
<value>En attente du test (appuyer sur Échap pour arrêter)...</value>
<value>En attente du test...</value>
</data>
<data name="SpeedtestingPressEscToExit" xml:space="preserve">
<value>Appuyer sur Échap pour arrêter</value>
</data>
<data name="TipDisplayLog" xml:space="preserve">
<value>Désactiver cette option si coupure anormale</value>

View File

@@ -976,7 +976,10 @@
<value>Hardveres gyorsítás engedélyezése (újraindítást igényel)</value>
</data>
<data name="SpeedtestingWait" xml:space="preserve">
<value>Tesztelésre vár (ESC megnyomásával megszakítható)...</value>
<value>Tesztelésre vár...</value>
</data>
<data name="SpeedtestingPressEscToExit" xml:space="preserve">
<value>ESC megnyomásával megszakítható</value>
</data>
<data name="TipDisplayLog" xml:space="preserve">
<value>Kérjük, kapcsolja ki rendellenes megszakadás esetén</value>

View File

@@ -976,7 +976,10 @@
<value>Enable hardware acceleration (requires restart)</value>
</data>
<data name="SpeedtestingWait" xml:space="preserve">
<value>Waiting for testing (press ESC to terminate)...</value>
<value>Waiting...</value>
</data>
<data name="SpeedtestingPressEscToExit" xml:space="preserve">
<value>Press ESC to terminate the test</value>
</data>
<data name="TipDisplayLog" xml:space="preserve">
<value>Please turn off when there is an abnormal disconnection</value>

View File

@@ -976,7 +976,10 @@
<value>Включить аппаратное ускорение (требуется перезагрузка)</value>
</data>
<data name="SpeedtestingWait" xml:space="preserve">
<value>Ожидание тестирования (нажмите ESC для отмены)…</value>
<value>Ожидание тестирования…</value>
</data>
<data name="SpeedtestingPressEscToExit" xml:space="preserve">
<value>нажмите ESC для отмены</value>
</data>
<data name="TipDisplayLog" xml:space="preserve">
<value>Отключите при аномальном разрыве соединения</value>

View File

@@ -976,7 +976,10 @@
<value>启用硬件加速 (需重启)</value>
</data>
<data name="SpeedtestingWait" xml:space="preserve">
<value>等待测试中 (按 ESC 终止)...</value>
<value>等待测试...</value>
</data>
<data name="SpeedtestingPressEscToExit" xml:space="preserve">
<value>按 ESC 可终止测试</value>
</data>
<data name="TipDisplayLog" xml:space="preserve">
<value>当有异常断流时请关闭</value>

View File

@@ -976,7 +976,10 @@
<value>啟用硬體加速 (需重啟)</value>
</data>
<data name="SpeedtestingWait" xml:space="preserve">
<value>等待測試中(按 ESC 終止)...</value>
<value>等待測試中...</value>
</data>
<data name="SpeedtestingPressEscToExit" xml:space="preserve">
<value>按 ECS 以終止測試</value>
</data>
<data name="TipDisplayLog" xml:space="preserve">
<value>當有異常斷流時請關閉</value>

View File

@@ -19,7 +19,7 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
public void ExitLoop()
{
if (_lstExitLoop.Count > 0)
if (!_lstExitLoop.IsEmpty)
{
_ = UpdateFunc("", ResUI.SpeedtestingStop);
@@ -27,6 +27,11 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
}
}
private static bool ShouldStopTest(string exitLoopKey)
{
return !_lstExitLoop.Any(p => p == exitLoopKey);
}
private async Task RunAsync(ESpeedActionType actionType, List<ProfileItem> selecteds)
{
var exitLoopKey = Utils.GetGuid(false);
@@ -103,6 +108,11 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
}
}
if (lstSelected.Count > 1 && (actionType == ESpeedActionType.Speedtest || actionType == ESpeedActionType.Mixedtest))
{
NoticeManager.Instance.Enqueue(ResUI.SpeedtestingPressEscToExit);
}
return lstSelected;
}
@@ -152,7 +162,7 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
var pageSizeNext = pageSize / 2;
if (lstFailed.Count > 0 && pageSizeNext > 0)
{
if (_lstExitLoop.Any(p => p == exitLoopKey) == false)
if (ShouldStopTest(exitLoopKey))
{
await UpdateFunc("", ResUI.SpeedtestingSkip);
return;
@@ -190,6 +200,12 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
{
continue;
}
if (ShouldStopTest(exitLoopKey))
{
return false;
}
tasks.Add(Task.Run(async () =>
{
await DoRealPing(it);
@@ -218,7 +234,7 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
List<Task> tasks = new();
foreach (var it in selecteds)
{
if (_lstExitLoop.Any(p => p == exitLoopKey) == false)
if (ShouldStopTest(exitLoopKey))
{
await UpdateFunc(it.IndexId, "", ResUI.SpeedtestingSkip);
continue;
@@ -234,13 +250,20 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
if (processService is null)
{
await UpdateFunc(it.IndexId, "", ResUI.FailedToRunCore);
return;
}
else
{
await Task.Delay(1000);
var delay = await DoRealPing(it);
if (blSpeedTest)
{
if (ShouldStopTest(exitLoopKey))
{
await UpdateFunc(it.IndexId, "", ResUI.SpeedtestingSkip);
return;
}
if (delay > 0)
{
await DoSpeedTest(downloadHandle, it);
@@ -251,7 +274,6 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
}
}
}
}
catch (Exception ex)
{
Logging.SaveLog(_tag, ex);