From 912f9a2bed0f7be9217ed08dc67bdff295b90c6d Mon Sep 17 00:00:00 2001 From: arm64v8a <48624112+arm64v8a@users.noreply.github.com> Date: Thu, 24 Aug 2023 16:16:19 +0900 Subject: [PATCH] feat: stop testing --- translations/fa_IR.ts | 4 ++++ translations/ru_RU.ts | 4 ++++ translations/zh_CN.ts | 4 ++++ ui/mainwindow.cpp | 3 +++ ui/mainwindow.ui | 6 ++++++ ui/mainwindow_grpc.cpp | 20 +++++++++++++++++++- 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/translations/fa_IR.ts b/translations/fa_IR.ts index e006930..cda7bdd 100644 --- a/translations/fa_IR.ts +++ b/translations/fa_IR.ts @@ -1552,6 +1552,10 @@ End: %2 Restart the program to take effect. برای مشاهده نتیجه برنامه را دوباره راه اندازی کنید + + Stop Testing + + ProxyItem diff --git a/translations/ru_RU.ts b/translations/ru_RU.ts index b73ca1c..52673f6 100644 --- a/translations/ru_RU.ts +++ b/translations/ru_RU.ts @@ -1561,6 +1561,10 @@ End: %2 Failed to stop, please restart the program. Не удалось остановить, пожалуйста, перезапустите приложение. + + Stop Testing + + ProxyItem diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index 9b9a4d0..ae5f7d9 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -1561,6 +1561,10 @@ Split by line. Test Options 测试选项 + + Stop Testing + 停止测试 + ProxyItem diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index c52b0b7..bcfded7 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -347,6 +347,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi connect(ui->menu_tcp_ping, &QAction::triggered, this, [=]() { speedtest_current_group(0); }); connect(ui->menu_url_test, &QAction::triggered, this, [=]() { speedtest_current_group(1); }); connect(ui->menu_full_test, &QAction::triggered, this, [=]() { speedtest_current_group(2); }); + connect(ui->menu_stop_testing, &QAction::triggered, this, [=]() { speedtest_current_group(114514); }); // auto set_selected_or_group = [=](int mode) { // 0=group 1=select 2=unknown(menu is hide) @@ -358,12 +359,14 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi ui->menuCurrent_Select->insertAction(ui->actionfake_4, ui->menu_tcp_ping); ui->menuCurrent_Select->insertAction(ui->actionfake_4, ui->menu_url_test); ui->menuCurrent_Select->insertAction(ui->actionfake_4, ui->menu_full_test); + ui->menuCurrent_Select->insertAction(ui->actionfake_4, ui->menu_stop_testing); ui->menuCurrent_Select->insertAction(ui->actionfake_4, ui->menu_clear_test_result); ui->menuCurrent_Select->insertAction(ui->actionfake_4, ui->menu_resolve_domain); } else { ui->menuCurrent_Group->insertAction(ui->actionfake_5, ui->menu_tcp_ping); ui->menuCurrent_Group->insertAction(ui->actionfake_5, ui->menu_url_test); ui->menuCurrent_Group->insertAction(ui->actionfake_5, ui->menu_full_test); + ui->menuCurrent_Group->insertAction(ui->actionfake_5, ui->menu_stop_testing); ui->menuCurrent_Group->insertAction(ui->actionfake_5, ui->menu_clear_test_result); ui->menuCurrent_Group->insertAction(ui->actionfake_5, ui->menu_resolve_domain); } diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 87a3138..8618965 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -536,6 +536,7 @@ + @@ -897,6 +898,11 @@ Restart Proxy + + + Stop Testing + + diff --git a/ui/mainwindow_grpc.cpp b/ui/mainwindow_grpc.cpp index fa0eb40..b355c9c 100644 --- a/ui/mainwindow_grpc.cpp +++ b/ui/mainwindow_grpc.cpp @@ -56,6 +56,7 @@ void MainWindow::setup_grpc() { // 测速 inline bool speedtesting = false; +inline QList speedtesting_threads = {}; void MainWindow::speedtest_current_group(int mode) { auto profiles = get_selected_or_group(); @@ -63,6 +64,16 @@ void MainWindow::speedtest_current_group(int mode) { auto group = NekoGui::profileManager->CurrentGroup(); if (group->archive) return; + // menu_stop_testing + if (mode == 114514) { + while (!speedtesting_threads.isEmpty()) { + auto t = speedtesting_threads.takeFirst(); + if (t != nullptr) t->exit(); + } + speedtesting = false; + return; + } + #ifndef NKR_NO_GRPC if (speedtesting) { MessageBoxWarning(software_name, "The last speed test did not exit completely, please wait. If it persists, please restart the program."); @@ -117,13 +128,20 @@ void MainWindow::speedtest_current_group(int mode) { lock_return.lock(); for (int i = 0; i < threadN; i++) { runOnNewThread([&] { + speedtesting_threads << QObject::thread(); + forever { // lock_write.lock(); if (profiles_test.isEmpty()) { threadN_finished++; - if (threadN == threadN_finished) lock_return.unlock(); + if (threadN == threadN_finished) { + // quit control thread + lock_return.unlock(); + } lock_write.unlock(); + // quit of this thread + speedtesting_threads.removeAll(QObject::thread()); return; } auto profile = profiles_test.takeFirst();