optimize code

This commit is contained in:
arm64v8a
2023-05-25 13:37:52 +09:00
parent ea993d8249
commit d7a8b939f3
5 changed files with 32 additions and 9 deletions

View File

@@ -622,7 +622,7 @@ namespace NekoGui {
status->result->outboundStats += ent->traffic_data; status->result->outboundStats += ent->traffic_data;
// mux common // mux common
auto needMux = ent->type == "vmess" || ent->type == "trojan" || ent->type == "vless" || ent->type == "shadowsocks"; auto needMux = ent->type == "vmess" || ent->type == "trojan" || ent->type == "vless";
needMux &= dataStore->mux_concurrency > 0; needMux &= dataStore->mux_concurrency > 0;
if (stream != nullptr) { if (stream != nullptr) {
@@ -637,17 +637,13 @@ namespace NekoGui {
} }
if (stream->multiplex_status == 0) { if (stream->multiplex_status == 0) {
if (!dataStore->mux_default_on) needMux = false; if (!dataStore->mux_default_on) needMux = false;
} else if (stream->multiplex_status == 1) {
needMux = true;
} else if (stream->multiplex_status == 2) { } else if (stream->multiplex_status == 2) {
needMux = false; needMux = false;
} }
} }
if (ent->type == "shadowsocks") {
if (!IS_NEKO_BOX || outbound["udp_over_tcp"] == true || !outbound["plugin"].isNull()) {
needMux = false;
}
}
// common // common
if (IS_NEKO_BOX) { if (IS_NEKO_BOX) {
// apply domain_strategy // apply domain_strategy

View File

@@ -1474,6 +1474,10 @@ End: %2</source>
<source>Failed to stop, please restart the program.</source> <source>Failed to stop, please restart the program.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Select mode, double-click or press Enter to select a profile, press ESC to exit.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProxyItem</name> <name>ProxyItem</name>

View File

@@ -1481,6 +1481,10 @@ Split by line.</source>
<source>If there is no response for a long time, it is recommended to restart the software.</source> <source>If there is no response for a long time, it is recommended to restart the software.</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Select mode, double-click or press Enter to select a profile, press ESC to exit.</source>
<translation>ESC键退出</translation>
</message>
</context> </context>
<context> <context>
<name>ProxyItem</name> <name>ProxyItem</name>

View File

@@ -67,6 +67,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
// Setup misc UI // Setup misc UI
themeManager->ApplyTheme(NekoGui::dataStore->theme); themeManager->ApplyTheme(NekoGui::dataStore->theme);
ui->setupUi(this); ui->setupUi(this);
//
connect(ui->menu_start, &QAction::triggered, this, [=]() { neko_start(); }); connect(ui->menu_start, &QAction::triggered, this, [=]() { neko_start(); });
connect(ui->menu_stop, &QAction::triggered, this, [=]() { neko_stop(); }); connect(ui->menu_stop, &QAction::triggered, this, [=]() { neko_stop(); });
connect(ui->tabWidget->tabBar(), &QTabBar::tabMoved, this, [=](int from, int to) { connect(ui->tabWidget->tabBar(), &QTabBar::tabMoved, this, [=](int from, int to) {
@@ -79,7 +80,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
}); });
ui->label_running->installEventFilter(this); ui->label_running->installEventFilter(this);
ui->label_inbound->installEventFilter(this); ui->label_inbound->installEventFilter(this);
ui->splitter->installEventFilter(this);
//
RegisterHotkey(false); RegisterHotkey(false);
//
auto last_size = NekoGui::dataStore->mw_size.split("x"); auto last_size = NekoGui::dataStore->mw_size.split("x");
if (last_size.length() == 2) { if (last_size.length() == 2) {
auto w = last_size[0].toInt(); auto w = last_size[0].toInt();
@@ -827,7 +831,12 @@ void MainWindow::refresh_status(const QString &traffic_update) {
// //
ui->checkBox_VPN->setChecked(NekoGui::dataStore->spmode_vpn); ui->checkBox_VPN->setChecked(NekoGui::dataStore->spmode_vpn);
ui->checkBox_SystemProxy->setChecked(NekoGui::dataStore->spmode_system_proxy); ui->checkBox_SystemProxy->setChecked(NekoGui::dataStore->spmode_system_proxy);
if (select_mode) ui->label_running->setText("[" + tr("Select") + "]"); if (select_mode) {
ui->label_running->setText(tr("Select") + " *");
ui->label_running->setToolTip(tr("Select mode, double-click or press Enter to select a profile, press ESC to exit."));
} else {
ui->label_running->setToolTip({});
}
auto make_title = [=](bool isTray) { auto make_title = [=](bool isTray) {
QStringList tt; QStringList tt;
@@ -1011,27 +1020,31 @@ void MainWindow::refresh_proxy_list_impl_refresh_data(const int &id) {
auto profile = NekoGui::profileManager->GetProfile(profileId); auto profile = NekoGui::profileManager->GetProfile(profileId);
if (profile == nullptr) continue; if (profile == nullptr) continue;
auto isRunning = profileId == NekoGui::dataStore->started_id;
auto f0 = std::make_unique<QTableWidgetItem>(); auto f0 = std::make_unique<QTableWidgetItem>();
f0->setData(114514, profileId); f0->setData(114514, profileId);
// Check state // Check state
auto check = f0->clone(); auto check = f0->clone();
check->setText(profileId == NekoGui::dataStore->started_id ? "" : Int2String(row + 1)); check->setText(isRunning ? "" : Int2String(row + 1));
ui->proxyListTable->setVerticalHeaderItem(row, check); ui->proxyListTable->setVerticalHeaderItem(row, check);
// C0: Type // C0: Type
auto f = f0->clone(); auto f = f0->clone();
f->setText(profile->bean->DisplayType()); f->setText(profile->bean->DisplayType());
if (isRunning) f->setForeground(palette().link());
ui->proxyListTable->setItem(row, 0, f); ui->proxyListTable->setItem(row, 0, f);
// C1: Address+Port // C1: Address+Port
f = f0->clone(); f = f0->clone();
f->setText(profile->bean->DisplayAddress()); f->setText(profile->bean->DisplayAddress());
if (isRunning) f->setForeground(palette().link());
ui->proxyListTable->setItem(row, 1, f); ui->proxyListTable->setItem(row, 1, f);
// C2: Name // C2: Name
f = f0->clone(); f = f0->clone();
f->setText(profile->bean->name); f->setText(profile->bean->name);
if (isRunning) f->setForeground(palette().link());
ui->proxyListTable->setItem(row, 2, f); ui->proxyListTable->setItem(row, 2, f);
// C3: Test Result // C3: Test Result
@@ -1612,6 +1625,11 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
on_menu_basic_settings_triggered(); on_menu_basic_settings_triggered();
return true; return true;
} }
} else if (event->type() == QEvent::MouseButtonDblClick) {
if (obj == ui->splitter) {
auto size = ui->splitter->size();
ui->splitter->setSizes({size.height() / 2, size.height() / 2});
}
} }
return QMainWindow::eventFilter(obj, event); return QMainWindow::eventFilter(obj, event);
} }

View File

@@ -278,6 +278,7 @@ void MainWindow::neko_start(int _id) {
} }
if (!mu_stopping.tryLock()) { if (!mu_stopping.tryLock()) {
MessageBoxWarning(software_name, "Another profile is stopping..."); MessageBoxWarning(software_name, "Another profile is stopping...");
mu_starting.unlock();
mu_stopping.unlock(); mu_stopping.unlock();
return; return;
} }