]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
WindowManager: move Wallet cleanup to different thread
authortobtoht <thotbot@protonmail.com>
Sat, 3 Jul 2021 01:29:13 +0000 (03:29 +0200)
committertobtoht <thotbot@protonmail.com>
Sat, 3 Jul 2021 01:29:13 +0000 (03:29 +0200)
src/MainWindow.cpp
src/MainWindow.h
src/WindowManager.cpp
src/WindowManager.h
src/appcontext.cpp
src/appcontext.h
src/dialog/AccountSwitcherDialog.cpp
src/dialog/TxInfoDialog.cpp

index dadde6e0c8555f4cbe8cd0ca42c9a4e4c7274390..0e7cc226bc469e816e8953d3a7918aff5e46c2c9 100644 (file)
@@ -368,8 +368,8 @@ void MainWindow::initWalletContext() {
     connect(m_ctx->nodes, &Nodes::WSNodeExhausted, this, &MainWindow::showWSNodeExhaustedMessage);
 
     // Wallet
-    connect(m_ctx->wallet.get(), &Wallet::connectionStatusChanged, this, &MainWindow::onConnectionStatusChanged);
-    connect(m_ctx->wallet.get(), &Wallet::currentSubaddressAccountChanged, this, &MainWindow::updateTitle);
+    connect(m_ctx->wallet, &Wallet::connectionStatusChanged, this, &MainWindow::onConnectionStatusChanged);
+    connect(m_ctx->wallet, &Wallet::currentSubaddressAccountChanged, this, &MainWindow::updateTitle);
 }
 
 void MainWindow::menuToggleTabVisible(const QString &key){
@@ -714,7 +714,7 @@ void MainWindow::showConnectionStatusDialog() {
 }
 
 void MainWindow::showPasswordDialog() {
-    PasswordChangeDialog dialog{this, m_ctx->wallet.get()};
+    PasswordChangeDialog dialog{this, m_ctx->wallet};
     dialog.exec();
     this->updatePasswordIcon();
 }
@@ -790,12 +790,12 @@ void MainWindow::menuSettingsClicked() {
 }
 
 void MainWindow::menuSignVerifyClicked() {
-    SignVerifyDialog dialog{m_ctx->wallet.get(), this};
+    SignVerifyDialog dialog{m_ctx->wallet, this};
     dialog.exec();
 }
 
 void MainWindow::menuVerifyTxProof() {
-    VerifyProofDialog dialog{m_ctx->wallet.get(), this};
+    VerifyProofDialog dialog{m_ctx->wallet, this};
     dialog.exec();
 }
 
@@ -845,6 +845,7 @@ void MainWindow::closeEvent(QCloseEvent *event) {
         m_txTimer.stop();
 
         this->saveGeo();
+        m_ctx->stopTimers();
         m_windowManager->closeWindow(this);
     }
 
@@ -1175,7 +1176,7 @@ void MainWindow::rescanSpent() {
 }
 
 void MainWindow::showBalanceDialog() {
-    BalanceDialog dialog{this, m_ctx->wallet.get()};
+    BalanceDialog dialog{this, m_ctx->wallet};
     dialog.exec();
 }
 
index 3d8557df4ae3afd691ac117f8b14c4e16583e0f9..212b62df0b546029411d117432adb92f46195443 100644 (file)
@@ -179,6 +179,8 @@ private slots:
     void onSetStatusText(const QString &text);
 
 private:
+    friend WindowManager;
+
     void initStatusBar();
     void initWidgets();
     void initMenu();
index 52177bcfbee6a93242bda349324d68e3ad6519fa..21fee866fcaf9c40247ca03eb1eb48790ee65a18 100644 (file)
@@ -17,6 +17,7 @@
 WindowManager::WindowManager() {
     m_walletManager = WalletManager::instance();
     m_splashDialog = new SplashDialog;
+    m_cleanupThread = new QThread();
 
     connect(m_walletManager, &WalletManager::walletOpened,        this, &WindowManager::onWalletOpened);
     connect(m_walletManager, &WalletManager::walletCreated,       this, &WindowManager::onWalletCreated);
@@ -68,6 +69,11 @@ void WindowManager::close() {
 
 void WindowManager::closeWindow(MainWindow *window) {
     m_windows.removeOne(window);
+
+    // Move Wallet to a different thread for cleanup so it doesn't block GUI thread
+    window->m_ctx->wallet->moveToThread(m_cleanupThread);
+    m_cleanupThread->start();
+    window->m_ctx->wallet->deleteLater();
 }
 
 void WindowManager::restartApplication(const QString &binaryFilename) {
index 2a87469c97305cbb305d9ab1ccef648b382eedef..c82c81b88d0c27bc200adb904b0fc7315649b5e4 100644 (file)
@@ -77,6 +77,8 @@ private:
     bool m_openWalletTriedOnce = false;
     bool m_openingWallet = false;
     bool m_initialNetworkConfigured = false;
+
+    QThread *m_cleanupThread;
 };
 
 
index df6630070e649431e2c89a7a345ffdcecd891ce0..a7c1dec22ca405bf96973726db0675a17bfb98e0 100644 (file)
@@ -27,22 +27,22 @@ AppContext::AppContext(Wallet *wallet)
     , networkType(constants::networkType)
     , m_rpc(new DaemonRpc{this, getNetworkTor(), ""})
 {
-    connect(this->wallet.get(), &Wallet::moneySpent,               this, &AppContext::onMoneySpent);
-    connect(this->wallet.get(), &Wallet::moneyReceived,            this, &AppContext::onMoneyReceived);
-    connect(this->wallet.get(), &Wallet::unconfirmedMoneyReceived, this, &AppContext::onUnconfirmedMoneyReceived);
-    connect(this->wallet.get(), &Wallet::newBlock,                 this, &AppContext::onWalletNewBlock);
-    connect(this->wallet.get(), &Wallet::updated,                  this, &AppContext::onWalletUpdate);
-    connect(this->wallet.get(), &Wallet::refreshed,                this, &AppContext::onWalletRefreshed);
-    connect(this->wallet.get(), &Wallet::transactionCommitted,     this, &AppContext::onTransactionCommitted);
-    connect(this->wallet.get(), &Wallet::heightRefreshed,          this, &AppContext::onHeightRefreshed);
-    connect(this->wallet.get(), &Wallet::transactionCreated,       this, &AppContext::onTransactionCreated);
-    connect(this->wallet.get(), &Wallet::deviceError,              this, &AppContext::onDeviceError);
-    connect(this->wallet.get(), &Wallet::deviceButtonRequest,      this, &AppContext::onDeviceButtonRequest);
-    connect(this->wallet.get(), &Wallet::deviceButtonPressed,      this, &AppContext::onDeviceButtonPressed);
-    connect(this->wallet.get(), &Wallet::connectionStatusChanged, [this]{
+    connect(this->wallet, &Wallet::moneySpent,               this, &AppContext::onMoneySpent);
+    connect(this->wallet, &Wallet::moneyReceived,            this, &AppContext::onMoneyReceived);
+    connect(this->wallet, &Wallet::unconfirmedMoneyReceived, this, &AppContext::onUnconfirmedMoneyReceived);
+    connect(this->wallet, &Wallet::newBlock,                 this, &AppContext::onWalletNewBlock);
+    connect(this->wallet, &Wallet::updated,                  this, &AppContext::onWalletUpdate);
+    connect(this->wallet, &Wallet::refreshed,                this, &AppContext::onWalletRefreshed);
+    connect(this->wallet, &Wallet::transactionCommitted,     this, &AppContext::onTransactionCommitted);
+    connect(this->wallet, &Wallet::heightRefreshed,          this, &AppContext::onHeightRefreshed);
+    connect(this->wallet, &Wallet::transactionCreated,       this, &AppContext::onTransactionCreated);
+    connect(this->wallet, &Wallet::deviceError,              this, &AppContext::onDeviceError);
+    connect(this->wallet, &Wallet::deviceButtonRequest,      this, &AppContext::onDeviceButtonRequest);
+    connect(this->wallet, &Wallet::deviceButtonPressed,      this, &AppContext::onDeviceButtonPressed);
+    connect(this->wallet, &Wallet::connectionStatusChanged, [this]{
         this->nodes->autoConnect();
     });
-    connect(this->wallet.get(), &Wallet::currentSubaddressAccountChanged, [this]{
+    connect(this->wallet, &Wallet::currentSubaddressAccountChanged, [this]{
         this->updateBalance();
     });
 
@@ -273,6 +273,10 @@ void AppContext::onOpenAliasResolve(const QString &openAlias) {
     emit openAliasResolveError(msg);
 }
 
+void AppContext::stopTimers() {
+    m_storeTimer.stop();
+}
+
 // ########################################## LIBWALLET QT SIGNALS ####################################################
 
 void AppContext::onMoneySpent(const QString &txId, quint64 amount) {
index 093c01c2ecdac813735b60c7999995b1cd2eea7d..39f9f6f538dfef77f00c9e8a6a0dcb5861de7557 100644 (file)
@@ -25,7 +25,7 @@ Q_OBJECT
 public:
     explicit AppContext(Wallet *wallet);
 
-    QScopedPointer<Wallet> wallet;
+    Wallet *wallet;
     Nodes *nodes;
 
     bool donationSending = false;
@@ -46,6 +46,8 @@ public:
 
     void storeWallet();
 
+    void stopTimers();
+
 public slots:
     void onCreateTransaction(const QString &address, quint64 amount, const QString &description, bool all);
     void onCreateTransactionMultiDest(const QVector<QString> &addresses, const QVector<quint64> &amounts, const QString &description);
index 5d28f49e274c988bf57f43f27219e9b610e27637..ee1e10e8b0c1caaaacb16395a9b3ed01d11b396a 100644 (file)
@@ -45,7 +45,7 @@ AccountSwitcherDialog::AccountSwitcherDialog(QSharedPointer<AppContext> ctx, QWi
        m_ctx->wallet->subaddressAccount()->refresh();
     });
 
-    connect(m_ctx->wallet.get(), &Wallet::currentSubaddressAccountChanged, this, &AccountSwitcherDialog::updateSelection);
+    connect(m_ctx->wallet, &Wallet::currentSubaddressAccountChanged, this, &AccountSwitcherDialog::updateSelection);
     connect(m_ctx->wallet->subaddressAccount(), &SubaddressAccount::refreshFinished, this, &AccountSwitcherDialog::updateSelection);
 
     this->updateSelection();
index 80ba5af86581804f7a133f14e1914124093143d8..f1df9888d3d38296189f99650b6f206e5cd9da4e 100644 (file)
@@ -30,7 +30,7 @@ TxInfoDialog::TxInfoDialog(QSharedPointer<AppContext> ctx, TransactionInfo *txIn
     connect(ui->btn_CopyTxKey, &QPushButton::pressed, this, &TxInfoDialog::copyTxKey);
     connect(ui->btn_createTxProof, &QPushButton::pressed, this, &TxInfoDialog::createTxProof);
 
-    connect(m_ctx->wallet.get(), &Wallet::newBlock, this, &TxInfoDialog::updateData);
+    connect(m_ctx->wallet, &Wallet::newBlock, this, &TxInfoDialog::updateData);
 
     this->setData(txInfo);