refactor: Remove call to StartShutdown from qt
Use interfaces::Node object instead. There is a minor change in behavior in this commit, because the new code calls InterruptRPC() and StopRPC() when previous code did not do this. But this should be a good thing since it makes sense to interrupt RPC when the system is shutting down, and it is better for the GUI shut down in a consistent way regardless of how the shutdown is triggered.
This commit is contained in:
1 parent
f0c73c1336
commit
f4a8bd6e2f
5 files changed
+12
-5
No files matched your search
+4
-1
@@ -661,7 +661,10 @@ int GuiMain(int argc, char* argv[])
|
|||||||
app.installEventFilter(new GUIUtil::LabelOutOfFocusEventFilter(&app));
|
app.installEventFilter(new GUIUtil::LabelOutOfFocusEventFilter(&app));
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
// Install global event filter for processing Windows session related Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION)
|
// Install global event filter for processing Windows session related Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION)
|
||||||
qApp->installNativeEventFilter(new WinShutdownMonitor());
|
// Note: it is safe to call app.node() in the lambda below despite the fact
|
||||||
|
// that app.createNode() hasn't been called yet, because native events will
|
||||||
|
// not be processed until the Qt event loop is executed.
|
||||||
|
qApp->installNativeEventFilter(new WinShutdownMonitor([&app] { app.node().startShutdown(); }));
|
||||||
#endif
|
#endif
|
||||||
// Install qDebug() message handler to route to debug.log
|
// Install qDebug() message handler to route to debug.log
|
||||||
qInstallMessageHandler(DebugMessageHandler);
|
qInstallMessageHandler(DebugMessageHandler);
|
||||||
|
|||||||
+1
-1
@@ -315,7 +315,7 @@ public Q_SLOTS:
|
|||||||
/** Simply calls showNormalIfMinimized(true) */
|
/** Simply calls showNormalIfMinimized(true) */
|
||||||
void toggleHidden();
|
void toggleHidden();
|
||||||
|
|
||||||
/** called by a timer to check if ShutdownRequested() has been set **/
|
/** called by a timer to check if shutdown has been requested */
|
||||||
void detectShutdown();
|
void detectShutdown();
|
||||||
|
|
||||||
/** Show progress dialog e.g. for verifychain */
|
/** Show progress dialog e.g. for verifychain */
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include <qt/bitcoingui.h>
|
#include <qt/bitcoingui.h>
|
||||||
#include <qt/networkstyle.h>
|
#include <qt/networkstyle.h>
|
||||||
#include <qt/rpcconsole.h>
|
#include <qt/rpcconsole.h>
|
||||||
#include <shutdown.h>
|
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <qt/winshutdownmonitor.h>
|
#include <qt/winshutdownmonitor.h>
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
#include <shutdown.h>
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@ bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, void *pM
|
|||||||
{
|
{
|
||||||
// Initiate a client shutdown after receiving a WM_QUERYENDSESSION and block
|
// Initiate a client shutdown after receiving a WM_QUERYENDSESSION and block
|
||||||
// Windows session end until we have finished client shutdown.
|
// Windows session end until we have finished client shutdown.
|
||||||
StartShutdown();
|
m_shutdown_fn();
|
||||||
*pnResult = FALSE;
|
*pnResult = FALSE;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include <windef.h> // for HWND
|
#include <windef.h> // for HWND
|
||||||
|
|
||||||
@@ -16,11 +17,16 @@
|
|||||||
class WinShutdownMonitor : public QAbstractNativeEventFilter
|
class WinShutdownMonitor : public QAbstractNativeEventFilter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
WinShutdownMonitor(std::function<void()> shutdown_fn) : m_shutdown_fn{std::move(shutdown_fn)} {}
|
||||||
|
|
||||||
/** Implements QAbstractNativeEventFilter interface for processing Windows messages */
|
/** Implements QAbstractNativeEventFilter interface for processing Windows messages */
|
||||||
bool nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pnResult) override;
|
bool nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pnResult) override;
|
||||||
|
|
||||||
/** Register the reason for blocking shutdown on Windows to allow clean client exit */
|
/** Register the reason for blocking shutdown on Windows to allow clean client exit */
|
||||||
static void registerShutdownBlockReason(const QString& strReason, const HWND& mainWinId);
|
static void registerShutdownBlockReason(const QString& strReason, const HWND& mainWinId);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::function<void()> m_shutdown_fn;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user