mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 12:34:37 +03:00
feat: stop testing
This commit is contained in:
@@ -1552,6 +1552,10 @@ End: %2</source>
|
||||
<source>Restart the program to take effect.</source>
|
||||
<translation type="unfinished">برای مشاهده نتیجه برنامه را دوباره راه اندازی کنید</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Stop Testing</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ProxyItem</name>
|
||||
|
||||
@@ -1561,6 +1561,10 @@ End: %2</source>
|
||||
<source>Failed to stop, please restart the program.</source>
|
||||
<translation>Не удалось остановить, пожалуйста, перезапустите приложение.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Stop Testing</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ProxyItem</name>
|
||||
|
||||
@@ -1561,6 +1561,10 @@ Split by line.</source>
|
||||
<source>Test Options</source>
|
||||
<translation>测试选项</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Stop Testing</source>
|
||||
<translation>停止测试</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ProxyItem</name>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -536,6 +536,7 @@
|
||||
<addaction name="menu_tcp_ping"/>
|
||||
<addaction name="menu_url_test"/>
|
||||
<addaction name="menu_full_test"/>
|
||||
<addaction name="menu_stop_testing"/>
|
||||
<addaction name="menu_clear_test_result"/>
|
||||
<addaction name="menu_resolve_domain"/>
|
||||
<addaction name="separator"/>
|
||||
@@ -897,6 +898,11 @@
|
||||
<string>Restart Proxy</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="menu_stop_testing">
|
||||
<property name="text">
|
||||
<string>Stop Testing</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
||||
@@ -56,6 +56,7 @@ void MainWindow::setup_grpc() {
|
||||
// 测速
|
||||
|
||||
inline bool speedtesting = false;
|
||||
inline QList<QThread *> 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();
|
||||
|
||||
Reference in New Issue
Block a user