This pull is based on a discussion with @TheBlueMatt and @laanwj.
- introduce a new StartShutdown() function, which starts a thread with Shutdown() if no GUI is used and calls uiInterface.QueueShutdown() if a GUI is used
- all direct uiInterface.QueueShutdown() calls are replaced with StartShutdown() - this ensures a clean GUI shutdown, even when catching a SIGTERM and allows the BitcoinGUI destructor to get called (which fixes a tray-icon issue and keeps the tray-icon until Bitcoin-Qt exits)
The current implementation (current master branch) sometimes crashes Bitcoin-Qt (bad) and doesn’t allow GUI object destructors do their work as we call exit() in Shutdown(), which leads to an unremoved tray-icon (as visible bug).
I’m sure we could remove some #include "ui_interface.h"
in the modified files, but I was not really sure about that, so input is welcome.
Fixes: #1182