Skip to content

Commit f4a8bd6

Browse files
committed
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.
1 parent f0c73c1 commit f4a8bd6

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

src/qt/bitcoin.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,10 @@ int GuiMain(int argc, char* argv[])
661661
app.installEventFilter(new GUIUtil::LabelOutOfFocusEventFilter(&app));
662662
#if defined(Q_OS_WIN)
663663
// Install global event filter for processing Windows session related Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION)
664-
qApp->installNativeEventFilter(new WinShutdownMonitor());
664+
// Note: it is safe to call app.node() in the lambda below despite the fact
665+
// that app.createNode() hasn't been called yet, because native events will
666+
// not be processed until the Qt event loop is executed.
667+
qApp->installNativeEventFilter(new WinShutdownMonitor([&app] { app.node().startShutdown(); }));
665668
#endif
666669
// Install qDebug() message handler to route to debug.log
667670
qInstallMessageHandler(DebugMessageHandler);

src/qt/bitcoingui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public Q_SLOTS:
315315
/** Simply calls showNormalIfMinimized(true) */
316316
void toggleHidden();
317317

318-
/** called by a timer to check if ShutdownRequested() has been set **/
318+
/** called by a timer to check if shutdown has been requested */
319319
void detectShutdown();
320320

321321
/** Show progress dialog e.g. for verifychain */

src/qt/test/apptests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <qt/bitcoingui.h>
1212
#include <qt/networkstyle.h>
1313
#include <qt/rpcconsole.h>
14-
#include <shutdown.h>
1514
#include <test/util/setup_common.h>
1615
#include <validation.h>
1716

src/qt/winshutdownmonitor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <qt/winshutdownmonitor.h>
66

77
#if defined(Q_OS_WIN)
8-
#include <shutdown.h>
98

109
#include <windows.h>
1110

@@ -25,7 +24,7 @@ bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, void *pM
2524
{
2625
// Initiate a client shutdown after receiving a WM_QUERYENDSESSION and block
2726
// Windows session end until we have finished client shutdown.
28-
StartShutdown();
27+
m_shutdown_fn();
2928
*pnResult = FALSE;
3029
return true;
3130
}

src/qt/winshutdownmonitor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifdef WIN32
99
#include <QByteArray>
1010
#include <QString>
11+
#include <functional>
1112

1213
#include <windef.h> // for HWND
1314

@@ -16,11 +17,16 @@
1617
class WinShutdownMonitor : public QAbstractNativeEventFilter
1718
{
1819
public:
20+
WinShutdownMonitor(std::function<void()> shutdown_fn) : m_shutdown_fn{std::move(shutdown_fn)} {}
21+
1922
/** Implements QAbstractNativeEventFilter interface for processing Windows messages */
2023
bool nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pnResult) override;
2124

2225
/** Register the reason for blocking shutdown on Windows to allow clean client exit */
2326
static void registerShutdownBlockReason(const QString& strReason, const HWND& mainWinId);
27+
28+
private:
29+
std::function<void()> m_shutdown_fn;
2430
};
2531
#endif
2632

0 commit comments

Comments
 (0)