From 9483325a68b5a7f297893c1dfeb3aa4caa681df5 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Fri, 3 May 2024 01:26:03 +0200 Subject: [PATCH] settings: fix proxy switch crash --- src/MainWindow.cpp | 15 +++++++-------- src/MainWindow.h | 3 ++- src/SettingsDialog.cpp | 1 + src/utils/nodes.h | 3 +-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index e612b5b..7000fb5 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -89,9 +89,7 @@ MainWindow::MainWindow(WindowManager *windowManager, Wallet *wallet, QWidget *pa connect(m_windowManager, &WindowManager::websocketStatusChanged, this, &MainWindow::onWebsocketStatusChanged); this->onWebsocketStatusChanged(!conf()->get(Config::disableWebsocket).toBool()); - connect(m_windowManager, &WindowManager::proxySettingsChanged, [this]{ - this->onProxySettingsChanged(); - }); + connect(m_windowManager, &WindowManager::proxySettingsChanged, this, &MainWindow::onProxySettingsChangedConnect); connect(m_windowManager, &WindowManager::updateBalance, m_wallet, &Wallet::updateBalance); connect(m_windowManager, &WindowManager::offlineMode, this, &MainWindow::onOfflineMode); connect(m_windowManager, &WindowManager::manualFeeSelectionEnabled, this, &MainWindow::onManualFeeSelectionEnabled); @@ -183,7 +181,7 @@ void MainWindow::initStatusBar() { m_statusBtnProxySettings = new StatusBarButton(icons()->icon("tor_logo_disabled.png"), "Proxy settings", this); connect(m_statusBtnProxySettings, &StatusBarButton::clicked, this, &MainWindow::menuProxySettingsClicked); this->statusBar()->addPermanentWidget(m_statusBtnProxySettings); - this->onProxySettingsChanged(false); + this->onProxySettingsChanged(); m_statusBtnHwDevice = new StatusBarButton(this->hardwareDevicePairedIcon(), this->getHardwareDevice(), this); connect(m_statusBtnHwDevice, &StatusBarButton::clicked, this, &MainWindow::menuHwDeviceClicked); @@ -651,11 +649,12 @@ void MainWindow::onWebsocketStatusChanged(bool enabled) { m_sendWidget->setWebsocketEnabled(enabled); } -void MainWindow::onProxySettingsChanged(bool connect) { - if (connect) { - m_nodes->connectToNode(); - } +void MainWindow::onProxySettingsChangedConnect() { + m_nodes->connectToNode(); + this->onProxySettingsChanged(); +} +void MainWindow::onProxySettingsChanged() { int proxy = conf()->get(Config::proxy).toInt(); if (proxy == Config::Proxy::Tor) { diff --git a/src/MainWindow.h b/src/MainWindow.h index f5786b0..ac9251e 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -165,7 +165,8 @@ private slots: void tryStoreWallet(); void onWebsocketStatusChanged(bool enabled); void showUpdateNotification(); - void onProxySettingsChanged(bool connect = true); + void onProxySettingsChangedConnect(); + void onProxySettingsChanged(); void onOfflineMode(bool offline); void onManualFeeSelectionEnabled(bool enabled); void onSubtractFeeFromAmountEnabled(bool enabled); diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index 37e69e4..9a84193 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -378,6 +378,7 @@ void Settings::onProxySettingsChanged() { ui->closeButton->addButton(QDialogButtonBox::Apply); connect(ui->closeButton->button(QDialogButtonBox::Apply), &QAbstractButton::clicked, [this](){ ui->proxyWidget->setProxySettings(); + m_nodes->updateModels(); emit proxySettingsChanged(); ui->closeButton->removeButton(ui->closeButton->button(QDialogButtonBox::Apply)); }); diff --git a/src/utils/nodes.h b/src/utils/nodes.h index c9166e0..27c2897 100644 --- a/src/utils/nodes.h +++ b/src/utils/nodes.h @@ -134,7 +134,6 @@ struct FeatherNode { } }; -class AppContext; class Nodes : public QObject { Q_OBJECT @@ -144,6 +143,7 @@ public: void loadConfig(); void allowConnection(); + void updateModels(); NodeSource source(); FeatherNode connection(); @@ -190,7 +190,6 @@ private: bool useI2PNodes(); bool useSocks5Proxy(const FeatherNode &node); - void updateModels(); void resetLocalState(); void exhausted(); int modeHeight(const QList &nodes);