add mozilla cert store support &&

fix c++ deprecation warnings
This commit is contained in:
Nova 2025-08-10 14:31:03 +03:30
parent 1fca654145
commit ffba194f7c
27 changed files with 211 additions and 199 deletions

View File

@ -104,6 +104,7 @@ namespace Configs {
bool skip_cert = false; bool skip_cert = false;
QString utlsFingerprint = ""; QString utlsFingerprint = "";
bool disable_run_admin = false; // windows only bool disable_run_admin = false; // windows only
bool use_mozilla_certs = false;
// Remember // Remember
QStringList remember_spmode = {}; QStringList remember_spmode = {};

View File

@ -887,6 +887,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="mozilla_cert">
<property name="text">
<string>Use Mozilla Certificate Store</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="skip_cert"> <widget class="QCheckBox" name="skip_cert">
<property name="text"> <property name="text">

View File

@ -5,7 +5,7 @@
namespace API { namespace API {
Client::Client(std::function<void(const QString &)> onError, const QString &host, int port) { Client::Client(std::function<void(const QString &)> onError, const QString &host, int port) {
this->make_rpc_client = [=]() { return std::make_unique<protorpc::Client>(host.toStdString().c_str(), port); }; this->make_rpc_client = [=,this]() { return std::make_unique<protorpc::Client>(host.toStdString().c_str(), port); };
this->onError = std::move(onError); this->onError = std::move(onError);
} }

View File

@ -932,6 +932,7 @@ namespace Configs {
} }
status->result->coreConfig.insert("log", QJsonObject{{"level", dataStore->log_level}}); status->result->coreConfig.insert("log", QJsonObject{{"level", dataStore->log_level}});
status->result->coreConfig.insert("certificate", QJsonObject{{"store", dataStore->use_mozilla_certs ? "mozilla" : "system"}});
status->result->coreConfig.insert("dns", dns); status->result->coreConfig.insert("dns", dns);
status->result->coreConfig.insert("inbounds", status->inbounds); status->result->coreConfig.insert("inbounds", status->inbounds);
status->result->coreConfig.insert("outbounds", status->outbounds); status->result->coreConfig.insert("outbounds", status->outbounds);

View File

@ -53,7 +53,7 @@ namespace Configs {
onFinished(); onFinished();
return; return;
} }
QHostInfo::lookupHost(serverAddress, QApplication::instance(), [=](const QHostInfo &host) { QHostInfo::lookupHost(serverAddress, QApplication::instance(), [=,this](const QHostInfo &host) {
auto addr = host.addresses(); auto addr = host.addresses();
if (!addr.isEmpty()) { if (!addr.isEmpty()) {
auto domain = serverAddress; auto domain = serverAddress;

View File

@ -668,7 +668,7 @@ namespace Subscription {
updated_order += ent; updated_order += ent;
} }
} catch (const fkyaml::exception &ex) { } catch (const fkyaml::exception &ex) {
runOnUiThread([=] { runOnUiThread([=,this] {
MessageBoxWarning("YAML Exception", ex.what()); MessageBoxWarning("YAML Exception", ex.what());
}); });
} }
@ -695,7 +695,7 @@ namespace Subscription {
if (items.indexOf(a) == 1) createNewGroup = true; if (items.indexOf(a) == 1) createNewGroup = true;
} }
runOnNewThread([=] { runOnNewThread([=,this] {
auto gid = _sub_gid; auto gid = _sub_gid;
if (createNewGroup) { if (createNewGroup) {
auto group = Configs::ProfileManager::NewGroup(); auto group = Configs::ProfileManager::NewGroup();

View File

@ -246,7 +246,7 @@ namespace Configs {
ent->fn = QString("profiles/%1.json").arg(ent->id); ent->fn = QString("profiles/%1.json").arg(ent->id);
} }
group->Save(); group->Save();
runOnNewThread([=] runOnNewThread([=,this]
{ {
for (const auto& ent : ents) ent->Save(); for (const auto& ent : ents) ent->Save();
}); });
@ -294,7 +294,7 @@ namespace Configs {
} }
profilesIdOrder = newOrder; profilesIdOrder = newOrder;
runOnNewThread([=] runOnNewThread([=,this]
{ {
for (int id : deleted_ids) QFile(QString("profiles/%1.json").arg(id)).remove(); for (int id : deleted_ids) QFile(QString("profiles/%1.json").arg(id)).remove();
}); });

View File

@ -313,6 +313,7 @@ namespace Configs {
_add(new configItem("disable_privilege_req", &disable_privilege_req, itemType::boolean)); _add(new configItem("disable_privilege_req", &disable_privilege_req, itemType::boolean));
_add(new configItem("enable_tun_routing", &enable_tun_routing, itemType::boolean)); _add(new configItem("enable_tun_routing", &enable_tun_routing, itemType::boolean));
_add(new configItem("speed_test_mode", &speed_test_mode, itemType::integer)); _add(new configItem("speed_test_mode", &speed_test_mode, itemType::integer));
_add(new configItem("use_mozilla_certs", &use_mozilla_certs, itemType::boolean));
} }
void DataStore::UpdateStartedId(int id) { void DataStore::UpdateStartedId(int id) {

View File

@ -84,7 +84,7 @@ namespace Stats
if (sort == Default) if (sort == Default)
{ {
runOnUiThread([=] { runOnUiThread([=,this] {
auto m = GetMainWindow(); auto m = GetMainWindow();
m->UpdateConnectionList(toUpdate, toAdd); m->UpdateConnectionList(toUpdate, toAdd);
}); });
@ -92,7 +92,7 @@ namespace Stats
{ {
if (sort == ByDownload) if (sort == ByDownload)
{ {
std::sort(sorted.begin(), sorted.end(), [=](const ConnectionMetadata& a, const ConnectionMetadata& b) std::sort(sorted.begin(), sorted.end(), [=,this](const ConnectionMetadata& a, const ConnectionMetadata& b)
{ {
if (a.download == b.download) return asc ? a.id > b.id : a.id < b.id; if (a.download == b.download) return asc ? a.id > b.id : a.id < b.id;
return asc ? a.download < b.download : a.download > b.download; return asc ? a.download < b.download : a.download > b.download;
@ -100,7 +100,7 @@ namespace Stats
} }
if (sort == ByUpload) if (sort == ByUpload)
{ {
std::sort(sorted.begin(), sorted.end(), [=](const ConnectionMetadata& a, const ConnectionMetadata& b) std::sort(sorted.begin(), sorted.end(), [=,this](const ConnectionMetadata& a, const ConnectionMetadata& b)
{ {
if (a.upload == b.upload) return asc ? a.id > b.id : a.id < b.id; if (a.upload == b.upload) return asc ? a.id > b.id : a.id < b.id;
return asc ? a.upload < b.upload : a.upload > b.upload; return asc ? a.upload < b.upload : a.upload > b.upload;
@ -108,7 +108,7 @@ namespace Stats
} }
if (sort == ByProcess) if (sort == ByProcess)
{ {
std::sort(sorted.begin(), sorted.end(), [=](const ConnectionMetadata& a, const ConnectionMetadata& b) std::sort(sorted.begin(), sorted.end(), [=,this](const ConnectionMetadata& a, const ConnectionMetadata& b)
{ {
if (a.process == b.process) return asc ? a.id > b.id : a.id < b.id; if (a.process == b.process) return asc ? a.id > b.id : a.id < b.id;
return asc ? a.process > b.process : a.process < b.process; return asc ? a.process > b.process : a.process < b.process;
@ -116,7 +116,7 @@ namespace Stats
} }
if (sort == ByOutbound) if (sort == ByOutbound)
{ {
std::sort(sorted.begin(), sorted.end(), [=](const ConnectionMetadata& a, const ConnectionMetadata& b) std::sort(sorted.begin(), sorted.end(), [=,this](const ConnectionMetadata& a, const ConnectionMetadata& b)
{ {
if (a.outbound == b.outbound) return asc ? a.id > b.id : a.id < b.id; if (a.outbound == b.outbound) return asc ? a.id > b.id : a.id < b.id;
return asc ? a.outbound > b.outbound : a.outbound < b.outbound; return asc ? a.outbound > b.outbound : a.outbound < b.outbound;
@ -124,13 +124,13 @@ namespace Stats
} }
if (sort == ByProtocol) if (sort == ByProtocol)
{ {
std::sort(sorted.begin(), sorted.end(), [=](const ConnectionMetadata& a, const ConnectionMetadata& b) std::sort(sorted.begin(), sorted.end(), [=,this](const ConnectionMetadata& a, const ConnectionMetadata& b)
{ {
if (a.protocol == b.protocol) return asc ? a.id > b.id : a.id < b.id; if (a.protocol == b.protocol) return asc ? a.id > b.id : a.id < b.id;
return asc ? a.protocol > b.protocol : a.protocol < b.protocol; return asc ? a.protocol > b.protocol : a.protocol < b.protocol;
}); });
} }
runOnUiThread([=] { runOnUiThread([=,this] {
auto m = GetMainWindow(); auto m = GetMainWindow();
m->UpdateConnectionListWithRecreate(sorted); m->UpdateConnectionListWithRecreate(sorted);
}); });

View File

@ -78,12 +78,12 @@ namespace Stats {
// 停止 // 停止
if (looping) { if (looping) {
looping = false; looping = false;
runOnUiThread([=] { runOnUiThread([=,this] {
auto m = GetMainWindow(); auto m = GetMainWindow();
m->refresh_status("STOP"); m->refresh_status("STOP");
}); });
} }
runOnUiThread([=] runOnUiThread([=,this]
{ {
auto m = GetMainWindow(); auto m = GetMainWindow();
m->update_traffic_graph(0, 0, 0, 0); m->update_traffic_graph(0, 0, 0, 0);
@ -104,7 +104,7 @@ namespace Stats {
loop_mutex.unlock(); loop_mutex.unlock();
// post to UI // post to UI
runOnUiThread([=] { runOnUiThread([=,this] {
auto m = GetMainWindow(); auto m = GetMainWindow();
if (proxy != nullptr) { if (proxy != nullptr) {
m->refresh_status(QObject::tr("Proxy: %1\nDirect: %2").arg(proxy->DisplaySpeed(), direct->DisplaySpeed())); m->refresh_status(QObject::tr("Proxy: %1\nDirect: %2").arg(proxy->DisplaySpeed(), direct->DisplaySpeed()));

View File

@ -75,7 +75,7 @@ namespace Configs_sys {
// Restart // Restart
start_profile_when_core_is_up = Configs::dataStore->started_id; start_profile_when_core_is_up = Configs::dataStore->started_id;
MW_show_log("[Fatal] " + QObject::tr("Core exited, restarting.")); MW_show_log("[Fatal] " + QObject::tr("Core exited, restarting."));
setTimeout([=] { Restart(); }, this, 200); setTimeout([=,this] { Restart(); }, this, 200);
} }
}); });
} }

View File

@ -50,7 +50,7 @@ GroupItem::GroupItem(QWidget *parent, const std::shared_ptr<Configs::Group> &ent
if (ent == nullptr) return; if (ent == nullptr) return;
connect(this, &GroupItem::edit_clicked, this, &GroupItem::on_edit_clicked); connect(this, &GroupItem::edit_clicked, this, &GroupItem::on_edit_clicked);
connect(Subscription::groupUpdater, &Subscription::GroupUpdater::asyncUpdateCallback, this, [=](int gid) { if (gid == this->ent->id) refresh_data(); }); connect(Subscription::groupUpdater, &Subscription::GroupUpdater::asyncUpdateCallback, this, [=,this](int gid) { if (gid == this->ent->id) refresh_data(); });
refresh_data(); refresh_data();
} }
@ -89,7 +89,7 @@ void GroupItem::refresh_data() {
} }
} }
runOnThread( runOnThread(
[=] { [=,this] {
adjustSize(); adjustSize();
item->setSizeHint(sizeHint()); item->setSizeHint(sizeHint());
dynamic_cast<QWidget *>(parent())->adjustSize(); dynamic_cast<QWidget *>(parent())->adjustSize();
@ -103,7 +103,7 @@ void GroupItem::on_update_sub_clicked() {
void GroupItem::on_edit_clicked() { void GroupItem::on_edit_clicked() {
auto dialog = new DialogEditGroup(ent, parentWindow); auto dialog = new DialogEditGroup(ent, parentWindow);
connect(dialog, &QDialog::finished, this, [=] { connect(dialog, &QDialog::finished, this, [=,this] {
if (dialog->result() == QDialog::Accepted) { if (dialog->result() == QDialog::Accepted) {
ent->Save(); ent->Save();
refresh_data(); refresh_data();

View File

@ -7,13 +7,13 @@
#include <QStringListModel> #include <QStringListModel>
#include <QCompleter> #include <QCompleter>
#define ADJUST_SIZE runOnThread([=] { adjustSize(); adjustPosition(mainwindow); }, this); #define ADJUST_SIZE runOnThread([=,this] { adjustSize(); adjustPosition(mainwindow); }, this);
DialogEditGroup::DialogEditGroup(const std::shared_ptr<Configs::Group> &ent, QWidget *parent) : QDialog(parent), ui(new Ui::DialogEditGroup) { DialogEditGroup::DialogEditGroup(const std::shared_ptr<Configs::Group> &ent, QWidget *parent) : QDialog(parent), ui(new Ui::DialogEditGroup) {
ui->setupUi(this); ui->setupUi(this);
this->ent = ent; this->ent = ent;
connect(ui->type, &QComboBox::currentIndexChanged, this, [=](int index) { connect(ui->type, &QComboBox::currentIndexChanged, this, [=,this](int index) {
ui->cat_sub->setHidden(index == 0); ui->cat_sub->setHidden(index == 0);
ADJUST_SIZE ADJUST_SIZE
}); });
@ -55,7 +55,7 @@ DialogEditGroup::DialogEditGroup(const std::shared_ptr<Configs::Group> &ent, QWi
frontCompleter->setFilterMode(Qt::MatchContains); frontCompleter->setFilterMode(Qt::MatchContains);
ui->front_proxy->setCompleter(nullptr); ui->front_proxy->setCompleter(nullptr);
ui->front_proxy->lineEdit()->setCompleter(frontCompleter); ui->front_proxy->lineEdit()->setCompleter(frontCompleter);
connect(ui->front_proxy, &QComboBox::currentTextChanged, this, [=](const QString &txt){ connect(ui->front_proxy, &QComboBox::currentTextChanged, this, [=,this](const QString &txt){
CACHE.front_proxy = get_proxy_id(txt); CACHE.front_proxy = get_proxy_id(txt);
}); });
@ -69,11 +69,11 @@ DialogEditGroup::DialogEditGroup(const std::shared_ptr<Configs::Group> &ent, QWi
landingCompleter->setFilterMode(Qt::MatchContains); landingCompleter->setFilterMode(Qt::MatchContains);
ui->landing_proxy->setCompleter(nullptr); ui->landing_proxy->setCompleter(nullptr);
ui->landing_proxy->lineEdit()->setCompleter(frontCompleter); ui->landing_proxy->lineEdit()->setCompleter(frontCompleter);
connect(ui->landing_proxy, &QComboBox::currentTextChanged, this, [=](const QString &txt){ connect(ui->landing_proxy, &QComboBox::currentTextChanged, this, [=,this](const QString &txt){
LANDING.landing_proxy = get_proxy_id(txt); LANDING.landing_proxy = get_proxy_id(txt);
}); });
connect(ui->copy_links, &QPushButton::clicked, this, [=] { connect(ui->copy_links, &QPushButton::clicked, this, [=,this] {
QStringList links; QStringList links;
for (const auto &[_, profile]: Configs::profileManager->profiles) { for (const auto &[_, profile]: Configs::profileManager->profiles) {
if (profile->gid != ent->id) continue; if (profile->gid != ent->id) continue;
@ -82,7 +82,7 @@ DialogEditGroup::DialogEditGroup(const std::shared_ptr<Configs::Group> &ent, QWi
QApplication::clipboard()->setText(links.join("\n")); QApplication::clipboard()->setText(links.join("\n"));
MessageBoxInfo(software_name, tr("Copied")); MessageBoxInfo(software_name, tr("Copied"));
}); });
connect(ui->copy_links_nkr, &QPushButton::clicked, this, [=] { connect(ui->copy_links_nkr, &QPushButton::clicked, this, [=,this] {
QStringList links; QStringList links;
for (const auto &[_, profile]: Configs::profileManager->profiles) { for (const auto &[_, profile]: Configs::profileManager->profiles) {
if (profile->gid != ent->id) continue; if (profile->gid != ent->id) continue;

View File

@ -27,7 +27,7 @@ DialogManageGroups::DialogManageGroups(QWidget *parent) : QDialog(parent), ui(ne
AddGroupToListIfExist(id) AddGroupToListIfExist(id)
} }
connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, [=](QListWidgetItem *wI) { connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, [=,this](QListWidgetItem *wI) {
auto w = dynamic_cast<GroupItem *>(ui->listWidget->itemWidget(wI)); auto w = dynamic_cast<GroupItem *>(ui->listWidget->itemWidget(wI));
emit w->edit_clicked(); emit w->edit_clicked();
}); });

View File

@ -63,8 +63,8 @@ void UI_InitMainWindow() {
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
mainwindow = this; mainwindow = this;
MW_dialog_message = [=](const QString &a, const QString &b) { MW_dialog_message = [=,this](const QString &a, const QString &b) {
runOnUiThread([=] runOnUiThread([=,this]
{ {
dialog_message_impl(a, b); dialog_message_impl(a, b);
}); });
@ -92,12 +92,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->masterLogBrowser->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); ui->masterLogBrowser->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
connect(qApp->styleHints(), &QStyleHints::colorSchemeChanged, this, [=](const Qt::ColorScheme& scheme) { connect(qApp->styleHints(), &QStyleHints::colorSchemeChanged, this, [=,this](const Qt::ColorScheme& scheme) {
new SyntaxHighlighter(scheme == Qt::ColorScheme::Dark, qvLogDocument); new SyntaxHighlighter(scheme == Qt::ColorScheme::Dark, qvLogDocument);
themeManager->ApplyTheme(Configs::dataStore->theme, true); themeManager->ApplyTheme(Configs::dataStore->theme, true);
}); });
#endif #endif
connect(themeManager, &ThemeManager::themeChanged, this, [=](const QString& theme){ connect(themeManager, &ThemeManager::themeChanged, this, [=,this](const QString& theme){
if (theme.toLower().contains("vista")) { if (theme.toLower().contains("vista")) {
// light themes // light themes
new SyntaxHighlighter(false, qvLogDocument); new SyntaxHighlighter(false, qvLogDocument);
@ -109,20 +109,20 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
new SyntaxHighlighter(isDarkMode(), qvLogDocument); new SyntaxHighlighter(isDarkMode(), qvLogDocument);
} }
}); });
connect(ui->masterLogBrowser->verticalScrollBar(), &QSlider::valueChanged, this, [=](int value) { connect(ui->masterLogBrowser->verticalScrollBar(), &QSlider::valueChanged, this, [=,this](int value) {
if (ui->masterLogBrowser->verticalScrollBar()->maximum() == value) if (ui->masterLogBrowser->verticalScrollBar()->maximum() == value)
qvLogAutoScoll = true; qvLogAutoScoll = true;
else else
qvLogAutoScoll = false; qvLogAutoScoll = false;
}); });
connect(ui->masterLogBrowser, &QTextBrowser::textChanged, this, [=]() { connect(ui->masterLogBrowser, &QTextBrowser::textChanged, this, [=,this]() {
if (!qvLogAutoScoll) if (!qvLogAutoScoll)
return; return;
auto bar = ui->masterLogBrowser->verticalScrollBar(); auto bar = ui->masterLogBrowser->verticalScrollBar();
bar->setValue(bar->maximum()); bar->setValue(bar->maximum());
}); });
MW_show_log = [=](const QString &log) { MW_show_log = [=,this](const QString &log) {
runOnUiThread([=] { show_log_impl(log); }); runOnUiThread([=,this] { show_log_impl(log); });
}; };
// Listen port if random // Listen port if random
@ -145,7 +145,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
// Start core // Start core
runOnThread( runOnThread(
[=] { [=,this] {
core_process = new Configs_sys::CoreProcess(core_path, args); core_process = new Configs_sys::CoreProcess(core_path, args);
// Remember last started // Remember last started
if (Configs::dataStore->remember_enable && Configs::dataStore->remember_id >= 0) { if (Configs::dataStore->remember_enable && Configs::dataStore->remember_id >= 0) {
@ -170,9 +170,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
parallelCoreCallPool->setMaxThreadCount(10); // constant value parallelCoreCallPool->setMaxThreadCount(10); // constant value
// //
connect(ui->menu_start, &QAction::triggered, this, [=]() { profile_start(); }); connect(ui->menu_start, &QAction::triggered, this, [=,this]() { profile_start(); });
connect(ui->menu_stop, &QAction::triggered, this, [=]() { profile_stop(false, false, true); }); connect(ui->menu_stop, &QAction::triggered, this, [=,this]() { profile_stop(false, false, true); });
connect(ui->tabWidget->tabBar(), &QTabBar::tabMoved, this, [=](int from, int to) { connect(ui->tabWidget->tabBar(), &QTabBar::tabMoved, this, [=,this](int from, int to) {
// use tabData to track tab & gid // use tabData to track tab & gid
Configs::profileManager->groupsTabOrder.clear(); Configs::profileManager->groupsTabOrder.clear();
for (int i = 0; i < ui->tabWidget->tabBar()->count(); i++) { for (int i = 0; i < ui->tabWidget->tabBar()->count(); i++) {
@ -220,7 +220,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->toolButton_server->setMenu(ui->menu_server); ui->toolButton_server->setMenu(ui->menu_server);
ui->toolButton_routing->setMenu(ui->menuRouting_Menu); ui->toolButton_routing->setMenu(ui->menuRouting_Menu);
ui->menubar->setVisible(false); ui->menubar->setVisible(false);
connect(ui->toolButton_update, &QToolButton::clicked, this, [=] { runOnNewThread([=] { CheckUpdate(); }); }); connect(ui->toolButton_update, &QToolButton::clicked, this, [=,this] { runOnNewThread([=,this] { CheckUpdate(); }); });
if (!QFile::exists(QApplication::applicationDirPath() + "/updater") && !QFile::exists(QApplication::applicationDirPath() + "/updater.exe")) if (!QFile::exists(QApplication::applicationDirPath() + "/updater") && !QFile::exists(QApplication::applicationDirPath() + "/updater.exe"))
{ {
ui->toolButton_update->hide(); ui->toolButton_update->hide();
@ -229,11 +229,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
// setup connection UI // setup connection UI
setupConnectionList(); setupConnectionList();
ui->stats_widget->tabBar()->setCurrentIndex(Configs::dataStore->stats_tab); ui->stats_widget->tabBar()->setCurrentIndex(Configs::dataStore->stats_tab);
connect(ui->stats_widget->tabBar(), &QTabBar::currentChanged, this, [=](int index) connect(ui->stats_widget->tabBar(), &QTabBar::currentChanged, this, [=,this](int index)
{ {
Configs::dataStore->stats_tab = ui->stats_widget->tabBar()->currentIndex(); Configs::dataStore->stats_tab = ui->stats_widget->tabBar()->currentIndex();
}); });
connect(ui->connections->horizontalHeader(), &QHeaderView::sectionClicked, this, [=](int index) connect(ui->connections->horizontalHeader(), &QHeaderView::sectionClicked, this, [=,this](int index)
{ {
Stats::ConnectionSort sortType; Stats::ConnectionSort sortType;
@ -255,7 +255,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->graph_tab->layout()->addWidget(speedChartWidget); ui->graph_tab->layout()->addWidget(speedChartWidget);
// table UI // table UI
ui->proxyListTable->rowsSwapped = [=](int row1, int row2) ui->proxyListTable->rowsSwapped = [=,this](int row1, int row2)
{ {
if (row1 == row2) return; if (row1 == row2) return;
auto group = Configs::profileManager->CurrentGroup(); auto group = Configs::profileManager->CurrentGroup();
@ -265,9 +265,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
}; };
if (auto button = ui->proxyListTable->findChild<QAbstractButton *>(QString(), Qt::FindDirectChildrenOnly)) { if (auto button = ui->proxyListTable->findChild<QAbstractButton *>(QString(), Qt::FindDirectChildrenOnly)) {
// Corner Button // Corner Button
connect(button, &QAbstractButton::clicked, this, [=] { refresh_proxy_list_impl(-1, {GroupSortMethod::ById}); }); connect(button, &QAbstractButton::clicked, this, [=,this] { refresh_proxy_list_impl(-1, {GroupSortMethod::ById}); });
} }
connect(ui->proxyListTable->horizontalHeader(), &QHeaderView::sectionClicked, this, [=](int logicalIndex) { connect(ui->proxyListTable->horizontalHeader(), &QHeaderView::sectionClicked, this, [=, this](int logicalIndex) {
GroupSortAction action; GroupSortAction action;
if (proxy_last_order == logicalIndex) { if (proxy_last_order == logicalIndex) {
action.descending = true; action.descending = true;
@ -290,7 +290,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
refresh_proxy_list_impl(-1, action); refresh_proxy_list_impl(-1, action);
Configs::profileManager->CurrentGroup()->Save(); Configs::profileManager->CurrentGroup()->Save();
}); });
connect(ui->proxyListTable->horizontalHeader(), &QHeaderView::sectionResized, this, [=](int logicalIndex, int oldSize, int newSize) { connect(ui->proxyListTable->horizontalHeader(), &QHeaderView::sectionResized, this, [=, this](int logicalIndex, int oldSize, int newSize) {
auto group = Configs::profileManager->CurrentGroup(); auto group = Configs::profileManager->CurrentGroup();
if (Configs::dataStore->refreshing_group || group == nullptr || !group->manually_column_width) return; if (Configs::dataStore->refreshing_group || group == nullptr || !group->manually_column_width) return;
// save manually column width // save manually column width
@ -305,7 +305,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->proxyListTable->setTabKeyNavigation(false); ui->proxyListTable->setTabKeyNavigation(false);
// search box // search box
connect(shortcut_esc, &QShortcut::activated, this, [=] { connect(shortcut_esc, &QShortcut::activated, this, [=,this] {
if (select_mode) { if (select_mode) {
emit profile_selected(-1); emit profile_selected(-1);
select_mode = false; select_mode = false;
@ -333,7 +333,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
trayMenu->addAction(ui->menu_exit); trayMenu->addAction(ui->menu_exit);
tray->setVisible(!Configs::dataStore->disable_tray); tray->setVisible(!Configs::dataStore->disable_tray);
tray->setContextMenu(trayMenu); tray->setContextMenu(trayMenu);
connect(tray, &QSystemTrayIcon::activated, qApp, [=](QSystemTrayIcon::ActivationReason reason) { connect(tray, &QSystemTrayIcon::activated, qApp, [=, this](QSystemTrayIcon::ActivationReason reason) {
if (reason == QSystemTrayIcon::Trigger) { if (reason == QSystemTrayIcon::Trigger) {
ActivateWindow(this); ActivateWindow(this);
} }
@ -344,41 +344,41 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->actionStart_with_system->setChecked(AutoRun_IsEnabled()); ui->actionStart_with_system->setChecked(AutoRun_IsEnabled());
ui->actionAllow_LAN->setChecked(QStringList{"::", "0.0.0.0"}.contains(Configs::dataStore->inbound_address)); ui->actionAllow_LAN->setChecked(QStringList{"::", "0.0.0.0"}.contains(Configs::dataStore->inbound_address));
connect(ui->menu_open_config_folder, &QAction::triggered, this, [=] { QDesktopServices::openUrl(QUrl::fromLocalFile(QDir::currentPath())); }); connect(ui->menu_open_config_folder, &QAction::triggered, this, [=,this] { QDesktopServices::openUrl(QUrl::fromLocalFile(QDir::currentPath())); });
connect(ui->menu_add_from_clipboard2, &QAction::triggered, ui->menu_add_from_clipboard, &QAction::trigger); connect(ui->menu_add_from_clipboard2, &QAction::triggered, ui->menu_add_from_clipboard, &QAction::trigger);
connect(ui->actionRestart_Proxy, &QAction::triggered, this, [=] { if (Configs::dataStore->started_id>=0) profile_start(Configs::dataStore->started_id); }); connect(ui->actionRestart_Proxy, &QAction::triggered, this, [=,this] { if (Configs::dataStore->started_id>=0) profile_start(Configs::dataStore->started_id); });
connect(ui->actionRestart_Program, &QAction::triggered, this, [=] { MW_dialog_message("", "RestartProgram"); }); connect(ui->actionRestart_Program, &QAction::triggered, this, [=,this] { MW_dialog_message("", "RestartProgram"); });
connect(ui->actionShow_window, &QAction::triggered, this, [=] { ActivateWindow(this); }); connect(ui->actionShow_window, &QAction::triggered, this, [=,this] { ActivateWindow(this); });
connect(ui->actionRemember_last_proxy, &QAction::triggered, this, [=](bool checked) { connect(ui->actionRemember_last_proxy, &QAction::triggered, this, [=,this](bool checked) {
Configs::dataStore->remember_enable = checked; Configs::dataStore->remember_enable = checked;
ui->actionRemember_last_proxy->setChecked(checked); ui->actionRemember_last_proxy->setChecked(checked);
Configs::dataStore->Save(); Configs::dataStore->Save();
}); });
connect(ui->actionStart_with_system, &QAction::triggered, this, [=](bool checked) { connect(ui->actionStart_with_system, &QAction::triggered, this, [=,this](bool checked) {
AutoRun_SetEnabled(checked); AutoRun_SetEnabled(checked);
ui->actionStart_with_system->setChecked(checked); ui->actionStart_with_system->setChecked(checked);
}); });
connect(ui->actionAllow_LAN, &QAction::triggered, this, [=](bool checked) { connect(ui->actionAllow_LAN, &QAction::triggered, this, [=,this](bool checked) {
Configs::dataStore->inbound_address = checked ? "::" : "127.0.0.1"; Configs::dataStore->inbound_address = checked ? "::" : "127.0.0.1";
ui->actionAllow_LAN->setChecked(checked); ui->actionAllow_LAN->setChecked(checked);
MW_dialog_message("", "UpdateDataStore"); MW_dialog_message("", "UpdateDataStore");
}); });
// //
connect(ui->checkBox_VPN, &QCheckBox::clicked, this, [=](bool checked) { set_spmode_vpn(checked); }); connect(ui->checkBox_VPN, &QCheckBox::clicked, this, [=,this](bool checked) { set_spmode_vpn(checked); });
connect(ui->checkBox_SystemProxy, &QCheckBox::clicked, this, [=](bool checked) { set_spmode_system_proxy(checked); }); connect(ui->checkBox_SystemProxy, &QCheckBox::clicked, this, [=,this](bool checked) { set_spmode_system_proxy(checked); });
connect(ui->menu_spmode, &QMenu::aboutToShow, this, [=]() { connect(ui->menu_spmode, &QMenu::aboutToShow, this, [=,this]() {
ui->menu_spmode_disabled->setChecked(!(Configs::dataStore->spmode_system_proxy || Configs::dataStore->spmode_vpn)); ui->menu_spmode_disabled->setChecked(!(Configs::dataStore->spmode_system_proxy || Configs::dataStore->spmode_vpn));
ui->menu_spmode_system_proxy->setChecked(Configs::dataStore->spmode_system_proxy); ui->menu_spmode_system_proxy->setChecked(Configs::dataStore->spmode_system_proxy);
ui->menu_spmode_vpn->setChecked(Configs::dataStore->spmode_vpn); ui->menu_spmode_vpn->setChecked(Configs::dataStore->spmode_vpn);
}); });
connect(ui->menu_spmode_system_proxy, &QAction::triggered, this, [=](bool checked) { set_spmode_system_proxy(checked); }); connect(ui->menu_spmode_system_proxy, &QAction::triggered, this, [=,this](bool checked) { set_spmode_system_proxy(checked); });
connect(ui->menu_spmode_vpn, &QAction::triggered, this, [=](bool checked) { set_spmode_vpn(checked); }); connect(ui->menu_spmode_vpn, &QAction::triggered, this, [=,this](bool checked) { set_spmode_vpn(checked); });
connect(ui->menu_spmode_disabled, &QAction::triggered, this, [=]() { connect(ui->menu_spmode_disabled, &QAction::triggered, this, [=,this]() {
set_spmode_system_proxy(false); set_spmode_system_proxy(false);
set_spmode_vpn(false); set_spmode_vpn(false);
}); });
connect(ui->menu_qr, &QAction::triggered, this, [=]() { display_qr_link(false); }); connect(ui->menu_qr, &QAction::triggered, this, [=,this]() { display_qr_link(false); });
connect(ui->system_dns, &QCheckBox::clicked, this, [=](bool checked) { connect(ui->system_dns, &QCheckBox::clicked, this, [=,this](bool checked) {
if (const auto ok = set_system_dns(checked); !ok) { if (const auto ok = set_system_dns(checked); !ok) {
ui->system_dns->setChecked(!checked); ui->system_dns->setChecked(!checked);
} else { } else {
@ -390,7 +390,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->system_dns->hide(); ui->system_dns->hide();
#endif #endif
connect(ui->menu_server, &QMenu::aboutToShow, this, [=](){ connect(ui->menu_server, &QMenu::aboutToShow, this, [=,this](){
if (running) if (running)
{ {
ui->actionSpeedtest_Current->setEnabled(true); ui->actionSpeedtest_Current->setEnabled(true);
@ -417,7 +417,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
} }
}); });
auto getRemoteRouteProfiles = [=] auto getRemoteRouteProfiles = [=,this]
{ {
auto resp = NetworkRequestHelper::HttpGet("https://api.github.com/repos/throneproj/routeprofiles/releases/latest"); auto resp = NetworkRequestHelper::HttpGet("https://api.github.com/repos/throneproj/routeprofiles/releases/latest");
if (resp.error.isEmpty()) { if (resp.error.isEmpty()) {
@ -437,7 +437,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
}; };
runOnNewThread(getRemoteRouteProfiles); runOnNewThread(getRemoteRouteProfiles);
connect(ui->menuRouting_Menu, &QMenu::aboutToShow, this, [=]() connect(ui->menuRouting_Menu, &QMenu::aboutToShow, this, [=,this]()
{ {
// refresh it on every menu show // refresh it on every menu show
runOnNewThread(getRemoteRouteProfiles); runOnNewThread(getRemoteRouteProfiles);
@ -450,11 +450,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
{ {
auto* action = new QAction(profilesMenu); auto* action = new QAction(profilesMenu);
action->setText(profile); action->setText(profile);
connect(action, &QAction::triggered, this, [=]() connect(action, &QAction::triggered, this, [=,this]()
{ {
auto resp = NetworkRequestHelper::HttpGet("https://github.com/throneproj/routeprofiles/releases/latest/download/" + profile + ".json"); auto resp = NetworkRequestHelper::HttpGet("https://github.com/throneproj/routeprofiles/releases/latest/download/" + profile + ".json");
if (!resp.error.isEmpty()) { if (!resp.error.isEmpty()) {
runOnUiThread([=] { runOnUiThread([=,this] {
MessageBoxWarning(QObject::tr("Download Profiles"), QObject::tr("Requesting profile error: %1").arg(resp.error + "\n" + resp.data)); MessageBoxWarning(QObject::tr("Download Profiles"), QObject::tr("Requesting profile error: %1").arg(resp.error + "\n" + resp.data));
}); });
return; return;
@ -462,7 +462,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
auto err = new QString; auto err = new QString;
auto parsed = Configs::RoutingChain::parseJsonArray(QString2QJsonArray(resp.data), err); auto parsed = Configs::RoutingChain::parseJsonArray(QString2QJsonArray(resp.data), err);
if (!err->isEmpty()) { if (!err->isEmpty()) {
runOnUiThread([=] runOnUiThread([=,this]
{ {
MessageBoxInfo(tr("Invalid JSON Array"), tr("The provided input cannot be parsed to a valid route rule array:\n") + *err); MessageBoxInfo(tr("Invalid JSON Array"), tr("The provided input cannot be parsed to a valid route rule array:\n") + *err);
}); });
@ -488,7 +488,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
action->setData(route.second->id); action->setData(route.second->id);
action->setCheckable(true); action->setCheckable(true);
action->setChecked(Configs::dataStore->routing->current_route_id == route.first); action->setChecked(Configs::dataStore->routing->current_route_id == route.first);
connect(action, &QAction::triggered, this, [=]() connect(action, &QAction::triggered, this, [=,this]()
{ {
auto routeID = action->data().toInt(); auto routeID = action->data().toInt();
if (Configs::dataStore->routing->current_route_id == routeID) return; if (Configs::dataStore->routing->current_route_id == routeID) return;
@ -499,39 +499,39 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->menuRouting_Menu->addAction(action); ui->menuRouting_Menu->addAction(action);
} }
}); });
connect(ui->actionUrl_Test_Selected, &QAction::triggered, this, [=]() { connect(ui->actionUrl_Test_Selected, &QAction::triggered, this, [=,this]() {
urltest_current_group(get_now_selected_list()); urltest_current_group(get_now_selected_list());
}); });
connect(ui->actionUrl_Test_Group, &QAction::triggered, this, [=]() { connect(ui->actionUrl_Test_Group, &QAction::triggered, this, [=,this]() {
urltest_current_group(Configs::profileManager->CurrentGroup()->GetProfileEnts()); urltest_current_group(Configs::profileManager->CurrentGroup()->GetProfileEnts());
}); });
connect(ui->actionSpeedtest_Current, &QAction::triggered, this, [=]() connect(ui->actionSpeedtest_Current, &QAction::triggered, this, [=,this]()
{ {
if (running != nullptr) if (running != nullptr)
{ {
speedtest_current_group({}, true); speedtest_current_group({}, true);
} }
}); });
connect(ui->actionSpeedtest_Selected, &QAction::triggered, this, [=]() connect(ui->actionSpeedtest_Selected, &QAction::triggered, this, [=,this]()
{ {
speedtest_current_group(get_now_selected_list()); speedtest_current_group(get_now_selected_list());
}); });
connect(ui->actionSpeedtest_Group, &QAction::triggered, this, [=]() connect(ui->actionSpeedtest_Group, &QAction::triggered, this, [=,this]()
{ {
speedtest_current_group(Configs::profileManager->CurrentGroup()->GetProfileEnts()); speedtest_current_group(Configs::profileManager->CurrentGroup()->GetProfileEnts());
}); });
connect(ui->menu_stop_testing, &QAction::triggered, this, [=]() { stopTests(); }); connect(ui->menu_stop_testing, &QAction::triggered, this, [=,this]() { stopTests(); });
// //
auto set_selected_or_group = [=](int mode) { auto set_selected_or_group = [=,this](int mode) {
// 0=group 1=select 2=unknown(menu is hide) // 0=group 1=select 2=unknown(menu is hide)
ui->menu_server->setProperty("selected_or_group", mode); ui->menu_server->setProperty("selected_or_group", mode);
}; };
connect(ui->menu_server, &QMenu::aboutToHide, this, [=] { connect(ui->menu_server, &QMenu::aboutToHide, this, [=,this] {
setTimeout([=] { set_selected_or_group(2); }, this, 200); setTimeout([=,this] { set_selected_or_group(2); }, this, 200);
}); });
set_selected_or_group(2); set_selected_or_group(2);
// //
connect(ui->menu_share_item, &QMenu::aboutToShow, this, [=] { connect(ui->menu_share_item, &QMenu::aboutToShow, this, [=,this] {
QString name; QString name;
auto selected = get_now_selected_list(); auto selected = get_now_selected_list();
if (!selected.isEmpty()) { if (!selected.isEmpty()) {
@ -546,7 +546,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
connect(qApp, &QGuiApplication::commitDataRequest, this, &MainWindow::on_commitDataRequest); connect(qApp, &QGuiApplication::commitDataRequest, this, &MainWindow::on_commitDataRequest);
auto t = new QTimer; auto t = new QTimer;
connect(t, &QTimer::timeout, this, [=]() { refresh_status(); }); connect(t, &QTimer::timeout, this, [=,this]() { refresh_status(); });
t->start(2000); t->start(2000);
t = new QTimer; t = new QTimer;
@ -569,7 +569,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
auto reset_interval = Configs::GeoAssets::ResetAssetsOptions[Configs::dataStore->auto_reset_assets_idx]; auto reset_interval = Configs::GeoAssets::ResetAssetsOptions[Configs::dataStore->auto_reset_assets_idx];
if (reset_interval > 0 && QDateTime::currentSecsSinceEpoch() - Configs::dataStore->last_asset_reset_epoch_secs > reset_interval) if (reset_interval > 0 && QDateTime::currentSecsSinceEpoch() - Configs::dataStore->last_asset_reset_epoch_secs > reset_interval)
{ {
runOnNewThread([=] runOnNewThread([=,this]
{ {
ResetAssets(Configs::dataStore->geoip_download_url, Configs::dataStore->geosite_download_url); ResetAssets(Configs::dataStore->geoip_download_url, Configs::dataStore->geosite_download_url);
}); });
@ -582,7 +582,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
if (Configs::NeedGeoAssets()) { if (Configs::NeedGeoAssets()) {
auto n = QMessageBox::warning(GetMessageBoxParent(), software_name, tr("Geo Assets are missing, want to download them now?"), QMessageBox::Yes | QMessageBox::No); auto n = QMessageBox::warning(GetMessageBoxParent(), software_name, tr("Geo Assets are missing, want to download them now?"), QMessageBox::Yes | QMessageBox::No);
if (n == QMessageBox::Yes) { if (n == QMessageBox::Yes) {
runOnNewThread([=] runOnNewThread([=,this]
{ {
DownloadAssets(!Configs::dataStore->geoip_download_url.isEmpty() ? Configs::dataStore->geoip_download_url : Configs::GeoAssets::GeoIPURLs[0], DownloadAssets(!Configs::dataStore->geoip_download_url.isEmpty() ? Configs::dataStore->geoip_download_url : Configs::GeoAssets::GeoIPURLs[0],
!Configs::dataStore->geosite_download_url.isEmpty() ? Configs::dataStore->geosite_download_url : Configs::GeoAssets::GeoSiteURLs[0]); !Configs::dataStore->geosite_download_url.isEmpty() ? Configs::dataStore->geosite_download_url : Configs::GeoAssets::GeoSiteURLs[0]);
@ -723,14 +723,14 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info)
} }
if (info.contains("DownloadAssets")) { if (info.contains("DownloadAssets")) {
auto splitted = info.split(";"); auto splitted = info.split(";");
runOnNewThread([=](){ runOnNewThread([=,this](){
DownloadAssets(splitted[1], splitted[2]); DownloadAssets(splitted[1], splitted[2]);
}); });
} }
if (info.contains("ResetAssets")) if (info.contains("ResetAssets"))
{ {
auto splitted = info.split(";"); auto splitted = info.split(";");
runOnNewThread([=](){ runOnNewThread([=,this](){
ResetAssets(splitted[1], splitted[2]); ResetAssets(splitted[1], splitted[2]);
}); });
} }
@ -807,7 +807,7 @@ inline bool dialog_is_using = false;
if (dialog_is_using) return; \ if (dialog_is_using) return; \
dialog_is_using = true; \ dialog_is_using = true; \
auto dialog = new a(this); \ auto dialog = new a(this); \
connect(dialog, &QDialog::finished, this, [=] { \ connect(dialog, &QDialog::finished, this, [=,this] { \
dialog->deleteLater(); \ dialog->deleteLater(); \
dialog_is_using = false; \ dialog_is_using = false; \
}); \ }); \
@ -883,7 +883,7 @@ void MainWindow::prepare_exit()
QMutex coreKillMu; QMutex coreKillMu;
coreKillMu.lock(); coreKillMu.lock();
runOnThread([=, &coreKillMu]() runOnThread([=, this, &coreKillMu]()
{ {
core_process->Kill(); core_process->Kill();
coreKillMu.unlock(); coreKillMu.unlock();
@ -951,7 +951,7 @@ bool MainWindow::get_elevated_permissions(int reason) {
} }
auto n = QMessageBox::warning(GetMessageBoxParent(), software_name, tr("Please give the core root privileges"), QMessageBox::Yes | QMessageBox::No); auto n = QMessageBox::warning(GetMessageBoxParent(), software_name, tr("Please give the core root privileges"), QMessageBox::Yes | QMessageBox::No);
if (n == QMessageBox::Yes) { if (n == QMessageBox::Yes) {
runOnNewThread([=] runOnNewThread([=,this]
{ {
auto chownArgs = QString("root:root " + Configs::FindCoreRealPath()); auto chownArgs = QString("root:root " + Configs::FindCoreRealPath());
auto ret = Linux_Run_Command("chown", chownArgs); auto ret = Linux_Run_Command("chown", chownArgs);
@ -1085,7 +1085,7 @@ void MainWindow::setupConnectionList()
ui->connections->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents); ui->connections->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
ui->connections->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents); ui->connections->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
ui->connections->verticalHeader()->hide(); ui->connections->verticalHeader()->hide();
connect(ui->connections, &QTableWidget::cellClicked, this, [=](int row, int column) connect(ui->connections, &QTableWidget::cellClicked, this, [=,this](int row, int column)
{ {
if (column > 3) return; if (column > 3) return;
auto selected = ui->connections->item(row, column); auto selected = ui->connections->item(row, column);
@ -1093,7 +1093,7 @@ void MainWindow::setupConnectionList()
QPoint pos = ui->connections->mapToGlobal(ui->connections->visualItemRect(selected).center()); QPoint pos = ui->connections->mapToGlobal(ui->connections->visualItemRect(selected).center());
QToolTip::showText(pos, "Copied!", this); QToolTip::showText(pos, "Copied!", this);
auto r = ++toolTipID; auto r = ++toolTipID;
QTimer::singleShot(1500, [=] { QTimer::singleShot(1500, [=,this] {
if (r != toolTipID) if (r != toolTipID)
{ {
return; return;
@ -1217,7 +1217,7 @@ void MainWindow::UpdateConnectionListWithRecreate(const QList<Stats::ConnectionM
} }
void MainWindow::refresh_status(const QString &traffic_update) { void MainWindow::refresh_status(const QString &traffic_update) {
auto refresh_speed_label = [=] { auto refresh_speed_label = [=,this] {
if (Configs::dataStore->disable_traffic_stats) { if (Configs::dataStore->disable_traffic_stats) {
ui->label_speed->setText(""); ui->label_speed->setText("");
} }
@ -1267,7 +1267,7 @@ void MainWindow::refresh_status(const QString &traffic_update) {
ui->label_running->setToolTip({}); ui->label_running->setToolTip({});
} }
auto make_title = [=](bool isTray) { auto make_title = [=,this](bool isTray) {
QStringList tt; QStringList tt;
if (!isTray && Configs::IsAdmin()) tt << "[Admin]"; if (!isTray && Configs::IsAdmin()) tt << "[Admin]";
if (select_mode) tt << "[" + tr("Select") + "]"; if (select_mode) tt << "[" + tr("Select") + "]";
@ -1392,7 +1392,7 @@ void MainWindow::refresh_proxy_list_impl(const int &id, GroupSortAction groupSor
case GroupSortMethod::ByLatency: case GroupSortMethod::ByLatency:
case GroupSortMethod::ByType: { case GroupSortMethod::ByType: {
std::sort(currentGroup->profiles.begin(), currentGroup->profiles.end(), std::sort(currentGroup->profiles.begin(), currentGroup->profiles.end(),
[=](int a, int b) { [=,this](int a, int b) {
QString ms_a; QString ms_a;
QString ms_b; QString ms_b;
if (groupSortAction.method == GroupSortMethod::ByType) { if (groupSortAction.method == GroupSortMethod::ByType) {
@ -1909,7 +1909,7 @@ void MainWindow::on_menu_remove_unavailable_triggered() {
} }
void MainWindow::on_menu_remove_invalid_triggered() { void MainWindow::on_menu_remove_invalid_triggered() {
runOnNewThread([=] runOnNewThread([=,this]
{ {
QList<std::shared_ptr<Configs::ProxyEntity>> out_del; QList<std::shared_ptr<Configs::ProxyEntity>> out_del;
@ -1945,7 +1945,7 @@ void MainWindow::on_menu_remove_invalid_triggered() {
} }
} }
runOnUiThread([=] runOnUiThread([=,this]
{ {
if (!out_del.empty() && if (!out_del.empty() &&
QMessageBox::question(this, tr("Confirmation"), tr("Remove %1 Invalid item(s) ?").arg(out_del.length()) + "\n" + remove_display) == QMessageBox::StandardButton::Yes) { QMessageBox::question(this, tr("Confirmation"), tr("Remove %1 Invalid item(s) ?").arg(out_del.length()) + "\n" + remove_display) == QMessageBox::StandardButton::Yes) {
@ -1970,7 +1970,7 @@ void MainWindow::on_menu_resolve_selected_triggered() {
Configs::dataStore->resolve_count = profiles.count(); Configs::dataStore->resolve_count = profiles.count();
for (const auto &profile: profiles) { for (const auto &profile: profiles) {
profile->bean->ResolveDomainToIP([=] { profile->bean->ResolveDomainToIP([=,this] {
profile->Save(); profile->Save();
if (--Configs::dataStore->resolve_count != 0) return; if (--Configs::dataStore->resolve_count != 0) return;
refresh_proxy_list(); refresh_proxy_list();
@ -1998,7 +1998,7 @@ void MainWindow::on_menu_resolve_domain_triggered() {
for (const auto id: profiles) { for (const auto id: profiles) {
auto profile = Configs::profileManager->GetProfile(id); auto profile = Configs::profileManager->GetProfile(id);
profile->bean->ResolveDomainToIP([=] { profile->bean->ResolveDomainToIP([=,this] {
profile->Save(); profile->Save();
if (--Configs::dataStore->resolve_count != 0) return; if (--Configs::dataStore->resolve_count != 0) return;
refresh_proxy_list(); refresh_proxy_list();
@ -2094,7 +2094,7 @@ void MainWindow::on_masterLogBrowser_customContextMenuRequested(const QPoint &po
auto action_clear = new QAction(this); auto action_clear = new QAction(this);
action_clear->setText(tr("Clear")); action_clear->setText(tr("Clear"));
connect(action_clear, &QAction::triggered, this, [=] { connect(action_clear, &QAction::triggered, this, [=,this] {
qvLogDocument->clear(); qvLogDocument->clear();
ui->masterLogBrowser->clear(); ui->masterLogBrowser->clear();
}); });
@ -2108,7 +2108,7 @@ void MainWindow::on_tabWidget_customContextMenuRequested(const QPoint &p) {
if (clickedIndex == -1) { if (clickedIndex == -1) {
auto* menu = new QMenu(this); auto* menu = new QMenu(this);
auto* addAction = new QAction(tr("Add new Group"), this); auto* addAction = new QAction(tr("Add new Group"), this);
connect(addAction, &QAction::triggered, this, [=]{ connect(addAction, &QAction::triggered, this, [=,this]{
auto ent = Configs::ProfileManager::NewGroup(); auto ent = Configs::ProfileManager::NewGroup();
auto dialog = new DialogEditGroup(ent, this); auto dialog = new DialogEditGroup(ent, this);
int ret = dialog->exec(); int ret = dialog->exec();
@ -2131,7 +2131,7 @@ void MainWindow::on_tabWidget_customContextMenuRequested(const QPoint &p) {
auto* addAction = new QAction(tr("Add new Group"), this); auto* addAction = new QAction(tr("Add new Group"), this);
auto* deleteAction = new QAction(tr("Delete selected Group"), this); auto* deleteAction = new QAction(tr("Delete selected Group"), this);
auto* editAction = new QAction(tr("Edit selected Group"), this); auto* editAction = new QAction(tr("Edit selected Group"), this);
connect(addAction, &QAction::triggered, this, [=]{ connect(addAction, &QAction::triggered, this, [=,this]{
auto ent = Configs::ProfileManager::NewGroup(); auto ent = Configs::ProfileManager::NewGroup();
auto dialog = new DialogEditGroup(ent, this); auto dialog = new DialogEditGroup(ent, this);
int ret = dialog->exec(); int ret = dialog->exec();
@ -2142,7 +2142,7 @@ void MainWindow::on_tabWidget_customContextMenuRequested(const QPoint &p) {
MW_dialog_message(Dialog_DialogManageGroups, "refresh-1"); MW_dialog_message(Dialog_DialogManageGroups, "refresh-1");
} }
}); });
connect(deleteAction, &QAction::triggered, this, [=] { connect(deleteAction, &QAction::triggered, this, [=,this] {
auto id = Configs::profileManager->groupsTabOrder[clickedIndex]; auto id = Configs::profileManager->groupsTabOrder[clickedIndex];
if (QMessageBox::question(this, tr("Confirmation"), tr("Remove %1?").arg(Configs::profileManager->groups[id]->name)) == if (QMessageBox::question(this, tr("Confirmation"), tr("Remove %1?").arg(Configs::profileManager->groups[id]->name)) ==
QMessageBox::StandardButton::Yes) { QMessageBox::StandardButton::Yes) {
@ -2150,11 +2150,11 @@ void MainWindow::on_tabWidget_customContextMenuRequested(const QPoint &p) {
MW_dialog_message(Dialog_DialogManageGroups, "refresh-1"); MW_dialog_message(Dialog_DialogManageGroups, "refresh-1");
} }
}); });
connect(editAction, &QAction::triggered, this, [=]{ connect(editAction, &QAction::triggered, this, [=,this]{
auto id = Configs::profileManager->groupsTabOrder[clickedIndex]; auto id = Configs::profileManager->groupsTabOrder[clickedIndex];
auto ent = Configs::profileManager->groups[id]; auto ent = Configs::profileManager->groups[id];
auto dialog = new DialogEditGroup(ent, this); auto dialog = new DialogEditGroup(ent, this);
connect(dialog, &QDialog::finished, this, [=] { connect(dialog, &QDialog::finished, this, [=,this] {
if (dialog->result() == QDialog::Accepted) { if (dialog->result() == QDialog::Accepted) {
ent->Save(); ent->Save();
MW_dialog_message(Dialog_DialogManageGroups, "refresh" + Int2String(ent->id)); MW_dialog_message(Dialog_DialogManageGroups, "refresh" + Int2String(ent->id));
@ -2252,7 +2252,7 @@ void MainWindow::RegisterHotkey(bool unregister) {
auto hk = std::make_shared<QHotkey>(k, true); auto hk = std::make_shared<QHotkey>(k, true);
if (hk->isRegistered()) { if (hk->isRegistered()) {
RegisteredHotkey += hk; RegisteredHotkey += hk;
connect(hk.get(), &QHotkey::activated, this, [=] { HotkeyEvent(key); }); connect(hk.get(), &QHotkey::activated, this, [=,this] { HotkeyEvent(key); });
} else { } else {
hk->deleteLater(); hk->deleteLater();
} }
@ -2261,7 +2261,7 @@ void MainWindow::RegisterHotkey(bool unregister) {
void MainWindow::RegisterShortcuts() { void MainWindow::RegisterShortcuts() {
for (const auto &action: ui->menuHidden_menu->actions()) { for (const auto &action: ui->menuHidden_menu->actions()) {
new QShortcut(action->shortcut(), this, [=](){ new QShortcut(action->shortcut(), this, [=,this](){
action->trigger(); action->trigger();
}); });
} }
@ -2269,7 +2269,7 @@ void MainWindow::RegisterShortcuts() {
void MainWindow::HotkeyEvent(const QString &key) { void MainWindow::HotkeyEvent(const QString &key) {
if (key.isEmpty()) return; if (key.isEmpty()) return;
runOnUiThread([=] { runOnUiThread([=,this] {
if (key == Configs::dataStore->hotkey_mainwindow) { if (key == Configs::dataStore->hotkey_mainwindow) {
tray->activated(QSystemTrayIcon::ActivationReason::Trigger); tray->activated(QSystemTrayIcon::ActivationReason::Trigger);
} else if (key == Configs::dataStore->hotkey_group) { } else if (key == Configs::dataStore->hotkey_group) {
@ -2287,7 +2287,7 @@ void MainWindow::HotkeyEvent(const QString &key) {
bool MainWindow::StopVPNProcess() { bool MainWindow::StopVPNProcess() {
QMutex waitStop; QMutex waitStop;
waitStop.lock(); waitStop.lock();
runOnThread([=, &waitStop] runOnThread([=, this, &waitStop]
{ {
core_process->Kill(); core_process->Kill();
waitStop.unlock(); waitStop.unlock();
@ -2300,7 +2300,7 @@ bool MainWindow::StopVPNProcess() {
void MainWindow::DownloadAssets(const QString &geoipUrl, const QString &geositeUrl) { void MainWindow::DownloadAssets(const QString &geoipUrl, const QString &geositeUrl) {
if (!mu_download_assets.tryLock()) { if (!mu_download_assets.tryLock()) {
runOnUiThread([=](){ runOnUiThread([=,this](){
MessageBoxWarning(tr("Cannot start"), tr("Last download request has not finished yet")); MessageBoxWarning(tr("Cannot start"), tr("Last download request has not finished yet"));
}); });
return; return;
@ -2323,7 +2323,7 @@ void MainWindow::DownloadAssets(const QString &geoipUrl, const QString &geositeU
} }
mu_download_assets.unlock(); mu_download_assets.unlock();
if (!errors.isEmpty()) { if (!errors.isEmpty()) {
runOnUiThread([=](){ runOnUiThread([=,this](){
MessageBoxWarning(tr("Failed to download geo assets"), errors); MessageBoxWarning(tr("Failed to download geo assets"), errors);
}); });
} }
@ -2346,7 +2346,7 @@ void MainWindow::ResetAssets(const QString& geoipUrl, const QString& geositeUrl)
} }
MW_show_log(tr("Removed all rule-set files")); MW_show_log(tr("Removed all rule-set files"));
runOnUiThread([=] runOnUiThread([=,this]
{ {
if (Configs::dataStore->started_id >= 0) profile_start(Configs::dataStore->started_id); if (Configs::dataStore->started_id >= 0) profile_start(Configs::dataStore->started_id);
}); });
@ -2450,7 +2450,7 @@ void MainWindow::CheckUpdate() {
# endif # endif
#endif #endif
if (search.isEmpty()) { if (search.isEmpty()) {
runOnUiThread([=] { runOnUiThread([=,this] {
MessageBoxWarning(QObject::tr("Update"), QObject::tr("Not official support platform")); MessageBoxWarning(QObject::tr("Update"), QObject::tr("Not official support platform"));
}); });
return; return;
@ -2458,7 +2458,7 @@ void MainWindow::CheckUpdate() {
auto resp = NetworkRequestHelper::HttpGet("https://api.github.com/repos/throneproj/Throne/releases"); auto resp = NetworkRequestHelper::HttpGet("https://api.github.com/repos/throneproj/Throne/releases");
if (!resp.error.isEmpty()) { if (!resp.error.isEmpty()) {
runOnUiThread([=] { runOnUiThread([=,this] {
MessageBoxWarning(QObject::tr("Update"), QObject::tr("Requesting update error: %1").arg(resp.error + "\n" + resp.data)); MessageBoxWarning(QObject::tr("Update"), QObject::tr("Requesting update error: %1").arg(resp.error + "\n" + resp.data));
}); });
return; return;
@ -2484,13 +2484,13 @@ void MainWindow::CheckUpdate() {
} }
if (release_download_url.isEmpty() || !isNewer(assets_name)) { if (release_download_url.isEmpty() || !isNewer(assets_name)) {
runOnUiThread([=] { runOnUiThread([=,this] {
MessageBoxInfo(QObject::tr("Update"), QObject::tr("No update")); MessageBoxInfo(QObject::tr("Update"), QObject::tr("No update"));
}); });
return; return;
} }
runOnUiThread([=] { runOnUiThread([=,this] {
auto allow_updater = !Configs::dataStore->flag_use_appdata; auto allow_updater = !Configs::dataStore->flag_use_appdata;
QMessageBox box(QMessageBox::Question, QObject::tr("Update") + note_pre_release, QMessageBox box(QMessageBox::Question, QObject::tr("Update") + note_pre_release,
QObject::tr("Update found: %1\nRelease note:\n%2").arg(assets_name, release_note)); QObject::tr("Update found: %1\nRelease note:\n%2").arg(assets_name, release_note));
@ -2505,9 +2505,9 @@ void MainWindow::CheckUpdate() {
// //
if (btn1 == box.clickedButton() && allow_updater) { if (btn1 == box.clickedButton() && allow_updater) {
// Download Update // Download Update
runOnNewThread([=] { runOnNewThread([=,this] {
if (!mu_download_update.tryLock()) { if (!mu_download_update.tryLock()) {
runOnUiThread([=](){ runOnUiThread([=,this](){
MessageBoxWarning(tr("Cannot start"), tr("Last download request has not finished yet")); MessageBoxWarning(tr("Cannot start"), tr("Last download request has not finished yet"));
}); });
return; return;
@ -2520,7 +2520,7 @@ void MainWindow::CheckUpdate() {
} }
} }
mu_download_update.unlock(); mu_download_update.unlock();
runOnUiThread([=] { runOnUiThread([=,this] {
if (errors.isEmpty()) { if (errors.isEmpty()) {
auto q = QMessageBox::question(nullptr, QObject::tr("Update"), auto q = QMessageBox::question(nullptr, QObject::tr("Update"),
QObject::tr("Update is ready, restart to install?")); QObject::tr("Update is ready, restart to install?"));

View File

@ -46,7 +46,7 @@ void MainWindow::runURLTest(const QString& config, bool useDefault, const QStrin
auto done = new QMutex; auto done = new QMutex;
done->lock(); done->lock();
runOnNewThread([=] runOnNewThread([=,this]
{ {
bool ok; bool ok;
while (true) while (true)
@ -88,7 +88,7 @@ void MainWindow::runURLTest(const QString& config, bool useDefault, const QStrin
} }
if (needRefresh) if (needRefresh)
{ {
runOnUiThread([=]{ runOnUiThread([=,this]{
refresh_proxy_list(); refresh_proxy_list();
}); });
} }
@ -177,7 +177,7 @@ void MainWindow::urltest_current_group(const QList<std::shared_ptr<Configs::Prox
speedtestRunning.lock(); speedtestRunning.lock();
speedtestRunning.unlock(); speedtestRunning.unlock();
runOnUiThread([=]{ runOnUiThread([=,this]{
refresh_proxy_list(); refresh_proxy_list();
MW_show_log(tr("URL test finished!")); MW_show_log(tr("URL test finished!"));
}); });
@ -198,7 +198,7 @@ void MainWindow::url_test_current() {
last_test_time = QTime::currentTime(); last_test_time = QTime::currentTime();
ui->label_running->setText(tr("Testing")); ui->label_running->setText(tr("Testing"));
runOnNewThread([=] { runOnNewThread([=,this] {
libcore::TestReq req; libcore::TestReq req;
req.test_current = true; req.test_current = true;
req.url = Configs::dataStore->test_latency_url.toStdString(); req.url = Configs::dataStore->test_latency_url.toStdString();
@ -210,7 +210,7 @@ void MainWindow::url_test_current() {
auto latency = result.results[0].latency_ms.value(); auto latency = result.results[0].latency_ms.value();
last_test_time = QTime::currentTime(); last_test_time = QTime::currentTime();
runOnUiThread([=] { runOnUiThread([=,this] {
if (!result.results[0].error.value().empty()) { if (!result.results[0].error.value().empty()) {
MW_show_log(QString("UrlTest error: %1").arg(QString::fromStdString(result.results[0].error.value()))); MW_show_log(QString("UrlTest error: %1").arg(QString::fromStdString(result.results[0].error.value())));
} }
@ -259,7 +259,7 @@ void MainWindow::speedtest_current_group(const QList<std::shared_ptr<Configs::Pr
} }
speedtestRunning.unlock(); speedtestRunning.unlock();
runOnUiThread([=]{ runOnUiThread([=,this]{
refresh_proxy_list(); refresh_proxy_list();
MW_show_log(tr("Speedtest finished!")); MW_show_log(tr("Speedtest finished!"));
}); });
@ -289,7 +289,7 @@ void MainWindow::runSpeedTest(const QString& config, bool useDefault, bool testC
// loop query result // loop query result
auto doneMu = new QMutex; auto doneMu = new QMutex;
doneMu->lock(); doneMu->lock();
runOnNewThread([=] runOnNewThread([=,this]
{ {
QDateTime lastProxyListUpdate = QDateTime::currentDateTime(); QDateTime lastProxyListUpdate = QDateTime::currentDateTime();
bool ok; bool ok;
@ -309,7 +309,7 @@ void MainWindow::runSpeedTest(const QString& config, bool useDefault, bool testC
{ {
continue; continue;
} }
runOnUiThread([=, &lastProxyListUpdate] runOnUiThread([=, this, &lastProxyListUpdate]
{ {
showSpeedtestData = true; showSpeedtestData = true;
currentSptProfileName = profile->bean->name; currentSptProfileName = profile->bean->name;
@ -326,7 +326,7 @@ void MainWindow::runSpeedTest(const QString& config, bool useDefault, bool testC
} }
}); });
} }
runOnUiThread([=] runOnUiThread([=, this]
{ {
showSpeedtestData = false; showSpeedtestData = false;
UpdateDataView(true); UpdateDataView(true);
@ -426,7 +426,7 @@ void MainWindow::profile_start(int _id) {
return; return;
} }
auto profile_start_stage2 = [=] { auto profile_start_stage2 = [=, this] {
libcore::LoadConfigReq req; libcore::LoadConfigReq req;
req.core_config = QJsonObject2QString(result->coreConfig, true).toStdString(); req.core_config = QJsonObject2QString(result->coreConfig, true).toStdString();
req.disable_stats = Configs::dataStore->disable_traffic_stats; req.disable_stats = Configs::dataStore->disable_traffic_stats;
@ -447,7 +447,7 @@ void MainWindow::profile_start(int _id) {
} }
if (!error.isEmpty()) { if (!error.isEmpty()) {
if (error.contains("configure tun interface")) { if (error.contains("configure tun interface")) {
runOnUiThread([=] { runOnUiThread([=, this] {
QMessageBox msg( QMessageBox msg(
QMessageBox::Information, QMessageBox::Information,
@ -469,7 +469,7 @@ void MainWindow::profile_start(int _id) {
}); });
return false; return false;
} }
runOnUiThread([=] { MessageBoxWarning("LoadConfig return error", error); }); runOnUiThread([=,this] { MessageBoxWarning("LoadConfig return error", error); });
return false; return false;
} }
// //
@ -483,7 +483,7 @@ void MainWindow::profile_start(int _id) {
Configs::dataStore->UpdateStartedId(ent->id); Configs::dataStore->UpdateStartedId(ent->id);
running = ent; running = ent;
runOnUiThread([=] { runOnUiThread([=, this] {
refresh_status(); refresh_status();
refresh_proxy_list(ent->id); refresh_proxy_list(ent->id);
}); });
@ -505,7 +505,7 @@ void MainWindow::profile_start(int _id) {
// check core state // check core state
if (!Configs::dataStore->core_running) { if (!Configs::dataStore->core_running) {
runOnThread( runOnThread(
[=] { [=, this] {
MW_show_log(tr("Try to start the config, but the core has not listened to the grpc port, so restart it...")); MW_show_log(tr("Try to start the config, but the core has not listened to the grpc port, so restart it..."));
core_process->start_profile_when_core_is_up = ent->id; core_process->start_profile_when_core_is_up = ent->id;
core_process->Restart(); core_process->Restart();
@ -518,13 +518,13 @@ void MainWindow::profile_start(int _id) {
// timeout message // timeout message
auto restartMsgbox = new QMessageBox(QMessageBox::Question, software_name, tr("If there is no response for a long time, it is recommended to restart the software."), auto restartMsgbox = new QMessageBox(QMessageBox::Question, software_name, tr("If there is no response for a long time, it is recommended to restart the software."),
QMessageBox::Yes | QMessageBox::No, this); QMessageBox::Yes | QMessageBox::No, this);
connect(restartMsgbox, &QMessageBox::accepted, this, [=] { MW_dialog_message("", "RestartProgram"); }); connect(restartMsgbox, &QMessageBox::accepted, this, [=,this] { MW_dialog_message("", "RestartProgram"); });
auto restartMsgboxTimer = new MessageBoxTimer(this, restartMsgbox, 5000); auto restartMsgboxTimer = new MessageBoxTimer(this, restartMsgbox, 5000);
runOnNewThread([=] { runOnNewThread([=, this] {
// stop current running // stop current running
if (running != nullptr) { if (running != nullptr) {
runOnUiThread([=] { profile_stop(false, true, true); }); runOnUiThread([=,this] { profile_stop(false, true, true); });
sem_stopped.acquire(); sem_stopped.acquire();
} }
// do start // do start
@ -534,7 +534,7 @@ void MainWindow::profile_start(int _id) {
} }
mu_starting.unlock(); mu_starting.unlock();
// cancel timeout // cancel timeout
runOnUiThread([=] { runOnUiThread([=,this] {
restartMsgboxTimer->cancel(); restartMsgboxTimer->cancel();
restartMsgboxTimer->deleteLater(); restartMsgboxTimer->deleteLater();
restartMsgbox->deleteLater(); restartMsgbox->deleteLater();
@ -571,12 +571,12 @@ void MainWindow::profile_stop(bool crash, bool sem, bool manual) {
return; return;
} }
auto profile_stop_stage2 = [=] { auto profile_stop_stage2 = [=,this] {
if (!crash) { if (!crash) {
bool rpcOK; bool rpcOK;
QString error = defaultClient->Stop(&rpcOK); QString error = defaultClient->Stop(&rpcOK);
if (rpcOK && !error.isEmpty()) { if (rpcOK && !error.isEmpty()) {
runOnUiThread([=] { MessageBoxWarning(tr("Stop return error"), error); }); runOnUiThread([=,this] { MessageBoxWarning(tr("Stop return error"), error); });
return false; return false;
} else if (!rpcOK) { } else if (!rpcOK) {
return false; return false;
@ -593,7 +593,7 @@ void MainWindow::profile_stop(bool crash, bool sem, bool manual) {
// timeout message // timeout message
auto restartMsgbox = new QMessageBox(QMessageBox::Question, software_name, tr("If there is no response for a long time, it is recommended to restart the software."), auto restartMsgbox = new QMessageBox(QMessageBox::Question, software_name, tr("If there is no response for a long time, it is recommended to restart the software."),
QMessageBox::Yes | QMessageBox::No, this); QMessageBox::Yes | QMessageBox::No, this);
connect(restartMsgbox, &QMessageBox::accepted, this, [=] { MW_dialog_message("", "RestartProgram"); }); connect(restartMsgbox, &QMessageBox::accepted, this, [=,this] { MW_dialog_message("", "RestartProgram"); });
auto restartMsgboxTimer = new MessageBoxTimer(this, restartMsgbox, 5000); auto restartMsgboxTimer = new MessageBoxTimer(this, restartMsgbox, 5000);
Stats::trafficLooper->loop_enabled = false; Stats::trafficLooper->loop_enabled = false;
@ -612,7 +612,7 @@ void MainWindow::profile_stop(bool crash, bool sem, bool manual) {
restartMsgboxTimer->deleteLater(); restartMsgboxTimer->deleteLater();
restartMsgbox->deleteLater(); restartMsgbox->deleteLater();
runOnNewThread([=] { runOnNewThread([=, this] {
// do stop // do stop
MW_show_log(">>>>>>>> " + tr("Stopping profile %1").arg(running->bean->DisplayTypeAndName())); MW_show_log(">>>>>>>> " + tr("Stopping profile %1").arg(running->bean->DisplayTypeAndName()));
if (!profile_stop_stage2()) { if (!profile_stop_stage2()) {
@ -625,7 +625,7 @@ void MainWindow::profile_stop(bool crash, bool sem, bool manual) {
if (sem) sem_stopped.release(); if (sem) sem_stopped.release();
runOnUiThread([=] { runOnUiThread([=, this] {
refresh_status(); refresh_status();
refresh_proxy_list_impl_refresh_data(id, true); refresh_proxy_list_impl_refresh_data(id, true);

View File

@ -26,7 +26,7 @@ void ProxyItem::refresh_data() {
ui->test_result->setText(ent->DisplayTestResult()); ui->test_result->setText(ent->DisplayTestResult());
runOnThread( runOnThread(
[=] { [=,this] {
adjustSize(); adjustSize();
item->setSizeHint(sizeHint()); item->setSizeHint(sizeHint());
dynamic_cast<QWidget *>(parent())->adjustSize(); dynamic_cast<QWidget *>(parent())->adjustSize();

View File

@ -20,7 +20,7 @@
#include <QInputDialog> #include <QInputDialog>
#include <QToolTip> #include <QToolTip>
#define ADJUST_SIZE runOnThread([=] { adjustSize(); adjustPosition(mainwindow); }, this); #define ADJUST_SIZE runOnThread([=,this] { adjustSize(); adjustPosition(mainwindow); }, this);
#define LOAD_TYPE(a) ui->type->addItem(Configs::ProfileManager::NewProxyEntity(a)->bean->DisplayType(), a); #define LOAD_TYPE(a) ui->type->addItem(Configs::ProfileManager::NewProxyEntity(a)->bean->DisplayType(), a);
DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId, QWidget *parent) DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId, QWidget *parent)
@ -31,7 +31,7 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId,
// network changed // network changed
network_title_base = ui->network_box->title(); network_title_base = ui->network_box->title();
connect(ui->network, &QComboBox::currentTextChanged, this, [=](const QString &txt) { connect(ui->network, &QComboBox::currentTextChanged, this, [=,this](const QString &txt) {
ui->network_box->setTitle(network_title_base.arg(txt)); ui->network_box->setTitle(network_title_base.arg(txt));
if (txt == "tcp") { if (txt == "tcp") {
ui->header_type->setVisible(true); ui->header_type->setVisible(true);
@ -111,7 +111,7 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId,
ui->network->removeItem(0); ui->network->removeItem(0);
// security changed // security changed
connect(ui->security, &QComboBox::currentTextChanged, this, [=](const QString &txt) { connect(ui->security, &QComboBox::currentTextChanged, this, [=,this](const QString &txt) {
if (txt == "tls") { if (txt == "tls") {
ui->security_box->setVisible(true); ui->security_box->setVisible(true);
ui->tls_camouflage_box->setVisible(true); ui->tls_camouflage_box->setVisible(true);
@ -135,13 +135,13 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId,
emit ui->security->currentTextChanged(ui->security->currentText()); emit ui->security->currentTextChanged(ui->security->currentText());
// for fragment // for fragment
connect(ui->tls_frag, &QCheckBox::checkStateChanged, this, [=](bool state) connect(ui->tls_frag, &QCheckBox::checkStateChanged, this, [=,this](bool state)
{ {
ui->tls_frag_fall_delay->setEnabled(state); ui->tls_frag_fall_delay->setEnabled(state);
}); });
// mux setting changed // mux setting changed
connect(ui->multiplex, &QComboBox::currentTextChanged, this, [=](const QString &txt) { connect(ui->multiplex, &QComboBox::currentTextChanged, this, [=,this](const QString &txt) {
if (txt == "Off") { if (txt == "Off") {
ui->brutal_enable->setCheckState(Qt::CheckState::Unchecked); ui->brutal_enable->setCheckState(Qt::CheckState::Unchecked);
ui->brutal_box->setEnabled(false); ui->brutal_box->setEnabled(false);
@ -174,7 +174,7 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId,
LOAD_TYPE("chain") LOAD_TYPE("chain")
// type changed // type changed
connect(ui->type, &QComboBox::currentIndexChanged, this, [=](int index) { connect(ui->type, &QComboBox::currentIndexChanged, this, [=,this](int index) {
typeSelected(ui->type->itemData(index).toString()); typeSelected(ui->type->itemData(index).toString());
}); });
@ -219,7 +219,7 @@ void DialogEditProfile::typeSelected(const QString &newType) {
auto _innerWidget = new EditTrojanVLESS(this); auto _innerWidget = new EditTrojanVLESS(this);
innerWidget = _innerWidget; innerWidget = _innerWidget;
innerEditor = _innerWidget; innerEditor = _innerWidget;
connect(_innerWidget->flow_, &QComboBox::currentTextChanged, _innerWidget, [=](const QString &txt) connect(_innerWidget->flow_, &QComboBox::currentTextChanged, _innerWidget, [=,this](const QString &txt)
{ {
if (txt == "xtls-rprx-vision") if (txt == "xtls-rprx-vision")
{ {
@ -347,7 +347,7 @@ void DialogEditProfile::typeSelected(const QString &newType) {
innerEditor->get_edit_text_name = [&]() { return ui->name->text(); }; innerEditor->get_edit_text_name = [&]() { return ui->name->text(); };
innerEditor->get_edit_text_serverAddress = [&]() { return ui->address->text(); }; innerEditor->get_edit_text_serverAddress = [&]() { return ui->address->text(); };
innerEditor->get_edit_text_serverPort = [&]() { return ui->port->text(); }; innerEditor->get_edit_text_serverPort = [&]() { return ui->port->text(); };
innerEditor->editor_cache_updated = [=] { editor_cache_updated_impl(); }; innerEditor->editor_cache_updated = [=,this] { editor_cache_updated_impl(); };
innerEditor->onStart(ent); innerEditor->onStart(ent);
// 左边 common // 左边 common
@ -407,7 +407,7 @@ void DialogEditProfile::typeSelected(const QString &newType) {
// 第一次显示 // 第一次显示
if (isHidden()) { if (isHidden()) {
runOnThread([=] { show(); }, this); runOnThread([=,this] { show(); }, this);
} }
} }
@ -576,7 +576,7 @@ void DialogEditProfile::on_apply_to_group_clicked() {
void DialogEditProfile::do_apply_to_group(const std::shared_ptr<Configs::Group> &group, QWidget *key) { void DialogEditProfile::do_apply_to_group(const std::shared_ptr<Configs::Group> &group, QWidget *key) {
auto stream = GetStreamSettings(ent->bean.get()); auto stream = GetStreamSettings(ent->bean.get());
auto copyStream = [=](void *p) { auto copyStream = [=,this](void *p) {
for (const auto &profile: group->GetProfileEnts()) { for (const auto &profile: group->GetProfileEnts()) {
auto newStream = GetStreamSettings(profile->bean.get()); auto newStream = GetStreamSettings(profile->bean.get());
if (newStream == nullptr) continue; if (newStream == nullptr) continue;
@ -587,7 +587,7 @@ void DialogEditProfile::do_apply_to_group(const std::shared_ptr<Configs::Group>
} }
}; };
auto copyBean = [=](void *p) { auto copyBean = [=,this](void *p) {
for (const auto &profile: group->GetProfileEnts()) { for (const auto &profile: group->GetProfileEnts()) {
if (profile == ent) continue; if (profile == ent) continue;
profile->bean->_setValue(ent->bean->_name(p), p); profile->bean->_setValue(ent->bean->_name(p), p);

View File

@ -42,7 +42,7 @@ bool EditChain::onEnd() {
void EditChain::on_select_profile_clicked() { void EditChain::on_select_profile_clicked() {
get_edit_dialog()->hide(); get_edit_dialog()->hide();
GetMainWindow()->start_select_mode(this, [=](int id) { GetMainWindow()->start_select_mode(this, [=,this](int id) {
get_edit_dialog()->show(); get_edit_dialog()->show();
AddProfileToListIfExist(id); AddProfileToListIfExist(id);
}); });
@ -57,9 +57,9 @@ void EditChain::AddProfileToListIfExist(int profileId) {
ui->listWidget->addItem(wI); ui->listWidget->addItem(wI);
ui->listWidget->setItemWidget(wI, w); ui->listWidget->setItemWidget(wI, w);
// change button // change button
connect(w->get_change_button(), &QPushButton::clicked, w, [=] { connect(w->get_change_button(), &QPushButton::clicked, w, [=,this] {
get_edit_dialog()->hide(); get_edit_dialog()->hide();
GetMainWindow()->start_select_mode(w, [=](int newId) { GetMainWindow()->start_select_mode(w, [=,this](int newId) {
get_edit_dialog()->show(); get_edit_dialog()->show();
ReplaceProfile(w, newId); ReplaceProfile(w, newId);
}); });

View File

@ -27,7 +27,7 @@ void EditExtraCore::onStart(std::shared_ptr<Configs::ProxyEntity> _ent) {
ui->path_combo->addItems(Configs::profileManager->GetExtraCorePaths()); ui->path_combo->addItems(Configs::profileManager->GetExtraCorePaths());
ui->path_combo->setCurrentText(bean->extraCorePath); ui->path_combo->setCurrentText(bean->extraCorePath);
connect(ui->path_button, &QPushButton::pressed, this, [=] connect(ui->path_button, &QPushButton::pressed, this, [=,this]
{ {
auto f = QFileDialog::getOpenFileName(); auto f = QFileDialog::getOpenFileName();
if (f.isEmpty()) if (f.isEmpty())

View File

@ -7,7 +7,7 @@
EditQUIC::EditQUIC(QWidget *parent) : QWidget(parent), ui(new Ui::EditQUIC) { EditQUIC::EditQUIC(QWidget *parent) : QWidget(parent), ui(new Ui::EditQUIC) {
ui->setupUi(this); ui->setupUi(this);
connect(ui->uuidgen, &QPushButton::clicked, this, [=] { ui->uuid->setText(QUuid::createUuid().toString().remove("{").remove("}")); }); connect(ui->uuidgen, &QPushButton::clicked, this, [=,this] { ui->uuid->setText(QUuid::createUuid().toString().remove("{").remove("}")); });
} }
EditQUIC::~EditQUIC() { EditQUIC::~EditQUIC() {

View File

@ -24,7 +24,7 @@ void EditSSH::onStart(std::shared_ptr<Configs::ProxyEntity> _ent) {
ui->host_key_algs->setText(bean->hostKeyAlgs.join(",")); ui->host_key_algs->setText(bean->hostKeyAlgs.join(","));
ui->client_version->setText(bean->clientVersion); ui->client_version->setText(bean->clientVersion);
connect(ui->choose_pk, &QPushButton::clicked, this, [=] { connect(ui->choose_pk, &QPushButton::clicked, this, [=,this] {
auto fn = QFileDialog::getOpenFileName(this, QObject::tr("Select"), QDir::currentPath(), auto fn = QFileDialog::getOpenFileName(this, QObject::tr("Select"), QDir::currentPath(),
"", nullptr, QFileDialog::Option::ReadOnly); "", nullptr, QFileDialog::Option::ReadOnly);
if (!fn.isEmpty()) { if (!fn.isEmpty()) {

View File

@ -6,7 +6,7 @@
EditVMess::EditVMess(QWidget *parent) : QWidget(parent), ui(new Ui::EditVMess) { EditVMess::EditVMess(QWidget *parent) : QWidget(parent), ui(new Ui::EditVMess) {
ui->setupUi(this); ui->setupUi(this);
connect(ui->uuidgen, &QPushButton::clicked, this, [=] { ui->uuid->setText(QUuid::createUuid().toString().remove("{").remove("}")); }); connect(ui->uuidgen, &QPushButton::clicked, this, [=,this] { ui->uuid->setText(QUuid::createUuid().toString().remove("{").remove("}")); });
} }
EditVMess::~EditVMess() { EditVMess::~EditVMess() {

View File

@ -72,7 +72,7 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<Configs::RoutingChai
ui->rule_attr_data->layout()->addWidget(rule_set_editor); ui->rule_attr_data->layout()->addWidget(rule_set_editor);
ui->rule_attr_data->adjustSize(); ui->rule_attr_data->adjustSize();
rule_set_editor->hide(); rule_set_editor->hide();
connect(rule_set_editor, &QPlainTextEdit::textChanged, this, [=]{ connect(rule_set_editor, &QPlainTextEdit::textChanged, this, [=,this]{
if (currentIndex == -1) return; if (currentIndex == -1) return;
auto currentVal = rule_set_editor->toPlainText().split('\n'); auto currentVal = rule_set_editor->toPlainText().split('\n');
chain->Rules[currentIndex]->set_field_value(ui->rule_attr->currentText(), currentVal); chain->Rules[currentIndex]->set_field_value(ui->rule_attr->currentText(), currentVal);
@ -145,7 +145,7 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<Configs::RoutingChai
simpleBlock->setPlainText(chain->GetSimpleRules(Configs::block)); simpleBlock->setPlainText(chain->GetSimpleRules(Configs::block));
simpleProxy->setPlainText(chain->GetSimpleRules(Configs::proxy)); simpleProxy->setPlainText(chain->GetSimpleRules(Configs::proxy));
connect(ui->tabWidget->tabBar(), &QTabBar::currentChanged, this, [=]() connect(ui->tabWidget->tabBar(), &QTabBar::currentChanged, this, [=,this]()
{ {
if (ui->tabWidget->tabBar()->currentIndex() == 1) if (ui->tabWidget->tabBar()->currentIndex() == 1)
{ {
@ -155,7 +155,7 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<Configs::RoutingChai
res += chain->UpdateSimpleRules(simpleProxy->toPlainText(), Configs::proxy); res += chain->UpdateSimpleRules(simpleProxy->toPlainText(), Configs::proxy);
if (!res.isEmpty()) if (!res.isEmpty())
{ {
runOnUiThread([=] runOnUiThread([=,this]
{ {
MessageBoxWarning(tr("Invalid rules"), tr("Some rules could not be added:\n") + res); MessageBoxWarning(tr("Invalid rules"), tr("Some rules could not be added:\n") + res);
}); });
@ -174,15 +174,15 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<Configs::RoutingChai
} }
}); });
connect(ui->howtouse_button, &QPushButton::clicked, this, [=]() connect(ui->howtouse_button, &QPushButton::clicked, this, [=,this]()
{ {
runOnUiThread([=] runOnUiThread([=,this]
{ {
MessageBoxInfo(tr("Simple rule manual"), Configs::Information::SimpleRuleInfo); MessageBoxInfo(tr("Simple rule manual"), Configs::Information::SimpleRuleInfo);
}); });
}); });
connect(ui->route_import_json, &QPushButton::clicked, this, [=] { connect(ui->route_import_json, &QPushButton::clicked, this, [=,this] {
auto w = new QDialog(this); auto w = new QDialog(this);
w->setWindowTitle("Import JSON Array"); w->setWindowTitle("Import JSON Array");
w->setWindowModality(Qt::ApplicationModal); w->setWindowModality(Qt::ApplicationModal);
@ -209,7 +209,7 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<Configs::RoutingChai
buttons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); buttons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
layout->addWidget(buttons, line, 0); layout->addWidget(buttons, line, 0);
connect(buttons, &QDialogButtonBox::accepted, w, [=]{ connect(buttons, &QDialogButtonBox::accepted, w, [=,this]{
auto err = new QString; auto err = new QString;
auto parsed = Configs::RoutingChain::parseJsonArray(QString2QJsonArray(tEdit->toPlainText()), err); auto parsed = Configs::RoutingChain::parseJsonArray(QString2QJsonArray(tEdit->toPlainText()), err);
if (!err->isEmpty()) { if (!err->isEmpty()) {
@ -229,13 +229,13 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<Configs::RoutingChai
w->deleteLater(); w->deleteLater();
}); });
connect(ui->rule_name, &QLineEdit::textChanged, this, [=](const QString& text) { connect(ui->rule_name, &QLineEdit::textChanged, this, [=,this](const QString& text) {
if (currentIndex == -1) return; if (currentIndex == -1) return;
chain->Rules[currentIndex]->name = QString(text); chain->Rules[currentIndex]->name = QString(text);
updateRouteItemsView(); updateRouteItemsView();
}); });
connect(ui->rule_attr_selector, &QComboBox::currentTextChanged, this, [=](const QString& text){ connect(ui->rule_attr_selector, &QComboBox::currentTextChanged, this, [=,this](const QString& text){
if (currentIndex == -1) return; if (currentIndex == -1) return;
if (ui->rule_attr->currentText() == "outbound") if (ui->rule_attr->currentText() == "outbound")
{ {
@ -247,33 +247,33 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<Configs::RoutingChai
updateRulePreview(); updateRulePreview();
}); });
connect(ui->rule_attr_text, &QPlainTextEdit::textChanged, this, [=] { connect(ui->rule_attr_text, &QPlainTextEdit::textChanged, this, [=,this] {
if (currentIndex == -1) return; if (currentIndex == -1) return;
auto currentVal = ui->rule_attr_text->toPlainText().split('\n'); auto currentVal = ui->rule_attr_text->toPlainText().split('\n');
chain->Rules[currentIndex]->set_field_value(ui->rule_attr->currentText(), currentVal); chain->Rules[currentIndex]->set_field_value(ui->rule_attr->currentText(), currentVal);
updateRulePreview(); updateRulePreview();
}); });
connect(ui->route_items, &QListWidget::currentRowChanged, this, [=](const int idx) { connect(ui->route_items, &QListWidget::currentRowChanged, this, [=,this](const int idx) {
if (idx == -1) return; if (idx == -1) return;
currentIndex = idx; currentIndex = idx;
updateRuleSection(); updateRuleSection();
}); });
connect(ui->rule_attr, &QComboBox::currentTextChanged, this, [=](const QString& text){ connect(ui->rule_attr, &QComboBox::currentTextChanged, this, [=,this](const QString& text){
updateRuleSection(); updateRuleSection();
}); });
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, [=]{ connect(ui->buttonBox, &QDialogButtonBox::accepted, this, [=,this]{
accept(); accept();
}); });
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [=]{ connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [=,this]{
QDialog::reject(); QDialog::reject();
}); });
deleteShortcut = new QShortcut(QKeySequence(Qt::Key_Delete), this); deleteShortcut = new QShortcut(QKeySequence(Qt::Key_Delete), this);
connect(deleteShortcut, &QShortcut::activated, this, [=]{ connect(deleteShortcut, &QShortcut::activated, this, [=,this]{
on_delete_route_item_clicked(); on_delete_route_item_clicked();
}); });
@ -314,7 +314,7 @@ void RouteItem::accept() {
res += chain->UpdateSimpleRules(simpleProxy->toPlainText(), Configs::proxy); res += chain->UpdateSimpleRules(simpleProxy->toPlainText(), Configs::proxy);
if (!res.isEmpty()) if (!res.isEmpty())
{ {
runOnUiThread([=] runOnUiThread([=,this]
{ {
MessageBoxWarning(tr("Invalid rules"), tr("Some rules could not be added, fix them before saving:\n") + res); MessageBoxWarning(tr("Invalid rules"), tr("Some rules could not be added, fix them before saving:\n") + res);
}); });

View File

@ -38,13 +38,13 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
ui->speedtest_mode->setCurrentIndex(Configs::dataStore->speed_test_mode); ui->speedtest_mode->setCurrentIndex(Configs::dataStore->speed_test_mode);
ui->simple_down_url->setText(Configs::dataStore->simple_dl_url); ui->simple_down_url->setText(Configs::dataStore->simple_dl_url);
connect(ui->custom_inbound_edit, &QPushButton::clicked, this, [=] { connect(ui->custom_inbound_edit, &QPushButton::clicked, this, [=,this] {
C_EDIT_JSON_ALLOW_EMPTY(custom_inbound) C_EDIT_JSON_ALLOW_EMPTY(custom_inbound)
}); });
connect(ui->disable_tray, &QCheckBox::stateChanged, this, [=](const bool &) { connect(ui->disable_tray, &QCheckBox::stateChanged, this, [=,this](const bool &) {
CACHE.updateDisableTray = true; CACHE.updateDisableTray = true;
}); });
connect(ui->random_listen_port, &QCheckBox::stateChanged, this, [=](const bool &state) connect(ui->random_listen_port, &QCheckBox::stateChanged, this, [=,this](const bool &state)
{ {
if (state) if (state)
{ {
@ -67,10 +67,10 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
D_LOAD_INT(max_log_line) D_LOAD_INT(max_log_line)
// //
ui->language->setCurrentIndex(Configs::dataStore->language); ui->language->setCurrentIndex(Configs::dataStore->language);
connect(ui->language, &QComboBox::currentIndexChanged, this, [=](int index) { connect(ui->language, &QComboBox::currentIndexChanged, this, [=,this](int index) {
CACHE.needRestart = true; CACHE.needRestart = true;
}); });
connect(ui->font, &QComboBox::currentTextChanged, this, [=](const QString &fontName) { connect(ui->font, &QComboBox::currentTextChanged, this, [=,this](const QString &fontName) {
auto font = qApp->font(); auto font = qApp->font();
font.setFamily(fontName); font.setFamily(fontName);
qApp->setFont(font); qApp->setFont(font);
@ -82,7 +82,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
ui->font_size->addItem(Int2String(i)); ui->font_size->addItem(Int2String(i));
} }
ui->font_size->setCurrentText(Int2String(qApp->font().pointSize())); ui->font_size->setCurrentText(Int2String(qApp->font().pointSize()));
connect(ui->font_size, &QComboBox::currentTextChanged, this, [=](const QString &sizeStr) { connect(ui->font_size, &QComboBox::currentTextChanged, this, [=,this](const QString &sizeStr) {
auto font = qApp->font(); auto font = qApp->font();
font.setPointSize(sizeStr.toInt()); font.setPointSize(sizeStr.toInt());
qApp->setFont(font); qApp->setFont(font);
@ -102,7 +102,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
ui->theme->setCurrentText(Configs::dataStore->theme); ui->theme->setCurrentText(Configs::dataStore->theme);
} }
// //
connect(ui->theme, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=](int index) { connect(ui->theme, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=,this](int index) {
themeManager->ApplyTheme(ui->theme->currentText()); themeManager->ApplyTheme(ui->theme->currentText());
Configs::dataStore->theme = ui->theme->currentText(); Configs::dataStore->theme = ui->theme->currentText();
Configs::dataStore->Save(); Configs::dataStore->Save();
@ -129,10 +129,10 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
ui->geosite_url->setCurrentText(Configs::dataStore->geosite_download_url); ui->geosite_url->setCurrentText(Configs::dataStore->geosite_download_url);
ui->auto_reset->setCurrentIndex(Configs::dataStore->auto_reset_assets_idx); ui->auto_reset->setCurrentIndex(Configs::dataStore->auto_reset_assets_idx);
connect(ui->download_geo_btn, &QPushButton::clicked, this, [=]() { connect(ui->download_geo_btn, &QPushButton::clicked, this, [=,this]() {
MW_dialog_message(Dialog_DialogBasicSettings, "DownloadAssets;"+ui->geoip_url->currentText()+";"+ui->geosite_url->currentText()); MW_dialog_message(Dialog_DialogBasicSettings, "DownloadAssets;"+ui->geoip_url->currentText()+";"+ui->geosite_url->currentText());
}); });
connect(ui->remove_srs_btn, &QPushButton::clicked, this, [=](){ connect(ui->remove_srs_btn, &QPushButton::clicked, this, [=,this](){
auto rsDir = QDir(RULE_SETS_DIR); auto rsDir = QDir(RULE_SETS_DIR);
auto entries = rsDir.entryList(QDir::Files); auto entries = rsDir.entryList(QDir::Files);
for (const auto &item: entries) { for (const auto &item: entries) {
@ -142,7 +142,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
} }
MW_show_log(tr("Removed all rule-set files")); MW_show_log(tr("Removed all rule-set files"));
}); });
connect(ui->reset_assets, &QPushButton::clicked, this, [=]() connect(ui->reset_assets, &QPushButton::clicked, this, [=,this]()
{ {
MW_dialog_message(Dialog_DialogBasicSettings, "ResetAssets;"+ui->geoip_url->currentText()+";"+ui->geosite_url->currentText()); MW_dialog_message(Dialog_DialogBasicSettings, "ResetAssets;"+ui->geoip_url->currentText()+";"+ui->geosite_url->currentText());
}); });
@ -161,7 +161,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
ui->ntp_server->setText(Configs::dataStore->ntp_server_address); ui->ntp_server->setText(Configs::dataStore->ntp_server_address);
ui->ntp_port->setText(Int2String(Configs::dataStore->ntp_server_port)); ui->ntp_port->setText(Int2String(Configs::dataStore->ntp_server_port));
ui->ntp_interval->setCurrentText(Configs::dataStore->ntp_interval); ui->ntp_interval->setCurrentText(Configs::dataStore->ntp_interval);
connect(ui->ntp_enable, &QCheckBox::stateChanged, this, [=](const bool &state) { connect(ui->ntp_enable, &QCheckBox::stateChanged, this, [=,this](const bool &state) {
ui->ntp_server->setEnabled(state); ui->ntp_server->setEnabled(state);
ui->ntp_port->setEnabled(state); ui->ntp_port->setEnabled(state);
ui->ntp_interval->setEnabled(state); ui->ntp_interval->setEnabled(state);
@ -172,6 +172,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
ui->utlsFingerprint->addItems(Preset::SingBox::UtlsFingerPrint); ui->utlsFingerprint->addItems(Preset::SingBox::UtlsFingerPrint);
ui->disable_priv_req->setChecked(Configs::dataStore->disable_privilege_req); ui->disable_priv_req->setChecked(Configs::dataStore->disable_privilege_req);
ui->windows_no_admin->setChecked(Configs::dataStore->disable_run_admin); ui->windows_no_admin->setChecked(Configs::dataStore->disable_run_admin);
ui->mozilla_cert->setChecked(Configs::dataStore->use_mozilla_certs);
D_LOAD_BOOL(skip_cert) D_LOAD_BOOL(skip_cert)
ui->utlsFingerprint->setCurrentText(Configs::dataStore->utlsFingerprint); ui->utlsFingerprint->setCurrentText(Configs::dataStore->utlsFingerprint);
@ -252,6 +253,7 @@ void DialogBasicSettings::accept() {
Configs::dataStore->utlsFingerprint = ui->utlsFingerprint->currentText(); Configs::dataStore->utlsFingerprint = ui->utlsFingerprint->currentText();
Configs::dataStore->disable_privilege_req = ui->disable_priv_req->isChecked(); Configs::dataStore->disable_privilege_req = ui->disable_priv_req->isChecked();
Configs::dataStore->disable_run_admin = ui->windows_no_admin->isChecked(); Configs::dataStore->disable_run_admin = ui->windows_no_admin->isChecked();
Configs::dataStore->use_mozilla_certs = ui->mozilla_cert->isChecked();
QStringList str{"UpdateDataStore"}; QStringList str{"UpdateDataStore"};
if (CACHE.needRestart) str << "NeedRestart"; if (CACHE.needRestart) str << "NeedRestart";
@ -304,7 +306,7 @@ void DialogBasicSettings::on_core_settings_clicked() {
auto box = new QDialogButtonBox; auto box = new QDialogButtonBox;
box->setOrientation(Qt::Horizontal); box->setOrientation(Qt::Horizontal);
box->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); box->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
connect(box, &QDialogButtonBox::accepted, w, [=] { connect(box, &QDialogButtonBox::accepted, w, [=,this] {
Configs::dataStore->core_box_underlying_dns = core_box_underlying_dns->text(); Configs::dataStore->core_box_underlying_dns = core_box_underlying_dns->text();
Configs::dataStore->core_box_clash_api = core_box_clash_api->text().toInt(); Configs::dataStore->core_box_clash_api = core_box_clash_api->text().toInt();
Configs::dataStore->core_box_clash_listen_addr = core_box_clash_listen_addr->text(); Configs::dataStore->core_box_clash_listen_addr = core_box_clash_listen_addr->text();

View File

@ -86,16 +86,16 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
ui->remote_dns_strategy->addItems(qsValue); ui->remote_dns_strategy->addItems(qsValue);
ui->enable_fakeip->setChecked(Configs::dataStore->fake_dns); ui->enable_fakeip->setChecked(Configs::dataStore->fake_dns);
// //
connect(ui->use_dns_object, &QCheckBox::stateChanged, this, [=](int state) { connect(ui->use_dns_object, &QCheckBox::stateChanged, this, [=,this](int state) {
auto useDNSObject = state == Qt::Checked; auto useDNSObject = state == Qt::Checked;
ui->simple_dns_box->setDisabled(useDNSObject); ui->simple_dns_box->setDisabled(useDNSObject);
ui->dns_object->setDisabled(!useDNSObject); ui->dns_object->setDisabled(!useDNSObject);
}); });
ui->use_dns_object->stateChanged(Qt::Unchecked); // uncheck to uncheck ui->use_dns_object->stateChanged(Qt::Unchecked); // uncheck to uncheck
connect(ui->dns_document, &QPushButton::clicked, this, [=] { connect(ui->dns_document, &QPushButton::clicked, this, [=,this] {
MessageBoxInfo("DNS", dnsHelpDocumentUrl); MessageBoxInfo("DNS", dnsHelpDocumentUrl);
}); });
connect(ui->format_dns_object, &QPushButton::clicked, this, [=] { connect(ui->format_dns_object, &QPushButton::clicked, this, [=,this] {
auto obj = QString2QJsonObject(ui->dns_object->toPlainText()); auto obj = QString2QJsonObject(ui->dns_object->toPlainText());
if (obj.isEmpty()) { if (obj.isEmpty()) {
MessageBoxInfo("DNS", "invaild json"); MessageBoxInfo("DNS", "invaild json");
@ -115,7 +115,7 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
ui->dns_final_out->setCurrentText(Configs::dataStore->routing->dns_final_out); ui->dns_final_out->setCurrentText(Configs::dataStore->routing->dns_final_out);
reloadProfileItems(); reloadProfileItems();
connect(ui->route_profiles, &QListWidget::itemDoubleClicked, this, [=](const QListWidgetItem* item){ connect(ui->route_profiles, &QListWidget::itemDoubleClicked, this, [=,this](const QListWidgetItem* item){
on_edit_route_clicked(); on_edit_route_clicked();
}); });
@ -123,7 +123,7 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
deleteShortcut = new QShortcut(QKeySequence(Qt::Key_Delete), this); deleteShortcut = new QShortcut(QKeySequence(Qt::Key_Delete), this);
connect(deleteShortcut, &QShortcut::activated, this, [=]{ connect(deleteShortcut, &QShortcut::activated, this, [=,this]{
on_delete_route_clicked(); on_delete_route_clicked();
}); });
@ -135,7 +135,7 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
ui->dnshijack_listenport->setText(Int2String(Configs::dataStore->dns_server_listen_port)); ui->dnshijack_listenport->setText(Int2String(Configs::dataStore->dns_server_listen_port));
ui->dnshijack_v4resp->setText(Configs::dataStore->dns_v4_resp); ui->dnshijack_v4resp->setText(Configs::dataStore->dns_v4_resp);
ui->dnshijack_v6resp->setText(Configs::dataStore->dns_v6_resp); ui->dnshijack_v6resp->setText(Configs::dataStore->dns_v6_resp);
connect(ui->dnshijack_what, &QPushButton::clicked, this, [=] { connect(ui->dnshijack_what, &QPushButton::clicked, this, [=,this] {
MessageBoxInfo("What is this?", Configs::Information::HijackInfo); MessageBoxInfo("What is this?", Configs::Information::HijackInfo);
}); });
@ -165,10 +165,10 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
ui->redirect_listenport->setValidator(QRegExpValidator_Number); ui->redirect_listenport->setValidator(QRegExpValidator_Number);
ui->redirect_listenport->setText(Int2String(Configs::dataStore->redirect_listen_port)); ui->redirect_listenport->setText(Int2String(Configs::dataStore->redirect_listen_port));
connect(ui->dnshijack_enable, &QCheckBox::stateChanged, this, [=](bool state) { connect(ui->dnshijack_enable, &QCheckBox::stateChanged, this, [=,this](bool state) {
set_dns_hijack_enability(state); set_dns_hijack_enability(state);
}); });
connect(ui->redirect_enable, &QCheckBox::stateChanged, this, [=](bool state) { connect(ui->redirect_enable, &QCheckBox::stateChanged, this, [=,this](bool state) {
ui->redirect_listenaddr->setEnabled(state); ui->redirect_listenaddr->setEnabled(state);
ui->redirect_listenport->setEnabled(state); ui->redirect_listenport->setEnabled(state);
}); });
@ -238,7 +238,7 @@ void DialogManageRoutes::on_new_route_clicked() {
routeChainWidget = new RouteItem(this, Configs::ProfileManager::NewRouteChain()); routeChainWidget = new RouteItem(this, Configs::ProfileManager::NewRouteChain());
routeChainWidget->setWindowModality(Qt::ApplicationModal); routeChainWidget->setWindowModality(Qt::ApplicationModal);
routeChainWidget->show(); routeChainWidget->show();
connect(routeChainWidget, &RouteItem::settingsChanged, this, [=](const std::shared_ptr<Configs::RoutingChain>& chain) { connect(routeChainWidget, &RouteItem::settingsChanged, this, [=,this](const std::shared_ptr<Configs::RoutingChain>& chain) {
chainList << chain; chainList << chain;
reloadProfileItems(); reloadProfileItems();
}); });
@ -259,7 +259,7 @@ void DialogManageRoutes::on_export_route_clicked()
QToolTip::showText(QCursor::pos(), "Copied!", this); QToolTip::showText(QCursor::pos(), "Copied!", this);
int r = ++tooltipID; int r = ++tooltipID;
QTimer::singleShot(1500, [=] { QTimer::singleShot(1500, [=,this] {
if (tooltipID != r) return; if (tooltipID != r) return;
QToolTip::hideText(); QToolTip::hideText();
}); });
@ -284,7 +284,7 @@ void DialogManageRoutes::on_edit_route_clicked() {
routeChainWidget = new RouteItem(this, chainList[idx]); routeChainWidget = new RouteItem(this, chainList[idx]);
routeChainWidget->setWindowModality(Qt::ApplicationModal); routeChainWidget->setWindowModality(Qt::ApplicationModal);
routeChainWidget->show(); routeChainWidget->show();
connect(routeChainWidget, &RouteItem::settingsChanged, this, [=](const std::shared_ptr<Configs::RoutingChain>& chain) { connect(routeChainWidget, &RouteItem::settingsChanged, this, [=,this](const std::shared_ptr<Configs::RoutingChain>& chain) {
if (currentRoute == chainList[idx]) currentRoute = chain; if (currentRoute == chainList[idx]) currentRoute = chain;
chainList[idx] = chain; chainList[idx] = chain;
reloadProfileItems(); reloadProfileItems();

View File

@ -9,7 +9,7 @@
#endif #endif
#include <QMessageBox> #include <QMessageBox>
#define ADJUST_SIZE runOnThread([=] { adjustSize(); adjustPosition(mainwindow); }, this); #define ADJUST_SIZE runOnThread([=,this] { adjustSize(); adjustPosition(mainwindow); }, this);
DialogVPNSettings::DialogVPNSettings(QWidget *parent) : QDialog(parent), ui(new Ui::DialogVPNSettings) { DialogVPNSettings::DialogVPNSettings(QWidget *parent) : QDialog(parent), ui(new Ui::DialogVPNSettings) {
ui->setupUi(this); ui->setupUi(this);
ADD_ASTERISK(this); ADD_ASTERISK(this);