diff --git a/pages/Mining.qml b/pages/Mining.qml index e45cfaf1..e147f43d 100644 --- a/pages/Mining.qml +++ b/pages/Mining.qml @@ -258,14 +258,18 @@ Rectangle { } } - function update() { + function onMiningStatus(isMining) { var daemonReady = walletManager.isDaemonLocal(appWindow.currentDaemonAddress) && appWindow.daemonSynced - appWindow.isMining = walletManager.isMining() + appWindow.isMining = isMining; updateStatusText() startSoloMinerButton.enabled = !appWindow.isMining && daemonReady stopSoloMinerButton.enabled = !startSoloMinerButton.enabled && daemonReady } + function update() { + walletManager.miningStatusAsync(); + } + MoneroComponents.StandardDialog { id: errorPopup cancelVisible: false @@ -286,4 +290,8 @@ Rectangle { function onPageClosed() { timer.running = false } + + Component.onCompleted: { + walletManager.miningStatus.connect(onMiningStatus); + } } diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index 124622db..b6581f25 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -389,6 +389,13 @@ bool WalletManager::isMining() const return m_pimpl->isMining(); } +void WalletManager::miningStatusAsync() const +{ + QtConcurrent::run([this] { + emit miningStatus(isMining()); + }); +} + bool WalletManager::startMining(const QString &address, quint32 threads, bool backgroundMining, bool ignoreBattery) { if(threads == 0) diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index ab4e4af7..6b7f8c3e 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -159,7 +159,7 @@ public: Q_INVOKABLE bool localDaemonSynced() const; Q_INVOKABLE bool isDaemonLocal(const QString &daemon_address) const; - Q_INVOKABLE bool isMining() const; + Q_INVOKABLE void miningStatusAsync() const; Q_INVOKABLE bool startMining(const QString &address, quint32 threads, bool backgroundMining, bool ignoreBattery); Q_INVOKABLE bool stopMining(); @@ -201,12 +201,16 @@ signals: void deviceButtonPressed(); void walletClosed(const QString &walletAddress); void checkUpdatesComplete(const QString &result) const; + void miningStatus(bool isMining) const; public slots: private: friend class WalletPassphraseListenerImpl; explicit WalletManager(QObject *parent = 0); + + bool isMining() const; + static WalletManager * m_instance; Monero::WalletManager * m_pimpl; mutable QMutex m_mutex;