From ab9e31e7cc5ab68a8291ff6ee1aa6d423484eea0 Mon Sep 17 00:00:00 2001 From: xiphon Date: Tue, 2 Jul 2019 10:57:37 +0000 Subject: [PATCH] WalletManager: async close with splash screen --- main.qml | 46 +++++++++++++++++-------------- pages/settings/SettingsInfo.qml | 9 +++--- src/libwalletqt/WalletManager.cpp | 6 ++-- src/libwalletqt/WalletManager.h | 3 +- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/main.qml b/main.qml index 743af497..c6300b52 100644 --- a/main.qml +++ b/main.qml @@ -283,7 +283,7 @@ ApplicationWindow { titleBar.visible = persistentSettings.customDecorations; } - function closeWallet() { + function closeWallet(callback) { // Disconnect all listeners if (typeof currentWallet !== "undefined" && currentWallet !== null) { @@ -306,8 +306,17 @@ ApplicationWindow { } currentWallet = undefined; - walletManager.closeWallet(); + appWindow.showProcessingSplash(qsTr("Closing wallet...")); + if (callback) { + walletManager.closeWalletAsync(function() { + hideProcessingSplash(); + callback(); + }); + } else { + walletManager.closeWallet(); + hideProcessingSplash(); + } } function connectWallet(wallet) { @@ -558,11 +567,6 @@ ApplicationWindow { } } - function onWalletClosed(walletAddress) { - hideProcessingSplash(); - console.log(">>> wallet closed: " + walletAddress) - } - function onWalletPassphraseNeeded(){ if(rootItem.state !== "normal") return; @@ -1115,17 +1119,18 @@ ApplicationWindow { function showWizard(){ clearMoneroCardLabelText(); walletInitialized = false; - closeWallet(); - currentWallet = undefined; - wizard.restart(); - wizard.wizardState = "wizardHome"; - rootItem.state = "wizard" - // reset balance - leftPanel.balanceText = leftPanel.unlockedBalanceText = walletManager.displayAmount(0); - fiatApiUpdateBalance(0, 0); - // disable timers - userInActivityTimer.running = false; - simpleModeConnectionTimer.running = false; + closeWallet(function() { + currentWallet = undefined; + wizard.restart(); + wizard.wizardState = "wizardHome"; + rootItem.state = "wizard" + // reset balance + leftPanel.balanceText = leftPanel.unlockedBalanceText = walletManager.displayAmount(0); + fiatApiUpdateBalance(0, 0); + // disable timers + userInActivityTimer.running = false; + simpleModeConnectionTimer.running = false; + }); } function hideMenu() { @@ -1289,7 +1294,6 @@ ApplicationWindow { y = (Screen.height - maxWindowHeight) / 2 // walletManager.walletOpened.connect(onWalletOpened); - walletManager.walletClosed.connect(onWalletClosed); walletManager.deviceButtonRequest.connect(onDeviceButtonRequest); walletManager.deviceButtonPressed.connect(onDeviceButtonPressed); walletManager.checkUpdatesComplete.connect(onWalletCheckUpdatesComplete); @@ -2131,8 +2135,8 @@ ApplicationWindow { console.log("close accepted"); // Close wallet non async on exit daemonManager.exit(); - walletManager.closeWallet(); - Qt.quit(); + + closeWallet(Qt.quit); } function onWalletCheckUpdatesComplete(update) { diff --git a/pages/settings/SettingsInfo.qml b/pages/settings/SettingsInfo.qml index b329c068..938bd122 100644 --- a/pages/settings/SettingsInfo.qml +++ b/pages/settings/SettingsInfo.qml @@ -208,10 +208,11 @@ Rectangle { confirmationDialog.icon = StandardIcon.Question confirmationDialog.cancelText = qsTr("Cancel") confirmationDialog.onAcceptedCallback = function() { - walletManager.closeWallet(); - walletManager.clearWalletCache(persistentSettings.wallet_path); - walletManager.openWalletAsync(persistentSettings.wallet_path, appWindow.walletPassword, - persistentSettings.nettype, persistentSettings.kdfRounds); + appWindow.closeWallet(function() { + walletManager.clearWalletCache(persistentSettings.wallet_path); + walletManager.openWalletAsync(persistentSettings.wallet_path, appWindow.walletPassword, + persistentSettings.nettype, persistentSettings.kdfRounds); + }); } confirmationDialog.onRejectedCallback = null; diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index 22a810b9..9b53ad6e 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -228,11 +228,11 @@ QString WalletManager::closeWallet() return result; } -void WalletManager::closeWalletAsync() +void WalletManager::closeWalletAsync(const QJSValue& callback) { m_scheduler.run([this] { - emit walletClosed(closeWallet()); - }); + return QJSValueList({closeWallet()}); + }, callback); } bool WalletManager::walletExists(const QString &path) const diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 18256b1c..54d2a29f 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -117,7 +117,7 @@ public: /*! * \brief closeWalletAsync - asynchronous version of "closeWallet" */ - Q_INVOKABLE void closeWalletAsync(); + Q_INVOKABLE void closeWalletAsync(const QJSValue& callback); //! checks is given filename is a wallet; Q_INVOKABLE bool walletExists(const QString &path) const; @@ -192,7 +192,6 @@ signals: void walletPassphraseNeeded(); void deviceButtonRequest(quint64 buttonCode); void deviceButtonPressed(); - void walletClosed(const QString &walletAddress); void checkUpdatesComplete(const QString &result) const; void miningStatus(bool isMining) const;