Browse Source

chatgui: add SetConsoleCtrlHandler for reliable Ctrl-C on Windows

topo_upd
Evgeny 2 months ago
parent
commit
faddbef32a
  1. 19
      tools/chatgui/src/main.cpp
  2. 5
      tools/chatgui/transport/utun_node.cpp

19
tools/chatgui/src/main.cpp

@ -3,10 +3,25 @@
#include <QStyleFactory>
#include <QDir>
#include <cstdio>
#ifdef _WIN32
#include <windows.h>
#endif
#include "mainwindow.h"
#include "../db/db_manager.h"
#include "../transport/node_config.h"
#ifdef _WIN32
extern "C" void utun_node_signal_shutdown(void);
static BOOL WINAPI console_ctrl_handler(DWORD dwCtrlType) {
if (dwCtrlType == CTRL_C_EVENT || dwCtrlType == CTRL_BREAK_EVENT) {
utun_node_signal_shutdown();
return TRUE;
}
return FALSE;
}
#endif
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
app.setApplicationName("Chat");
@ -76,5 +91,9 @@ int main(int argc, char *argv[]) {
cfg.debugLevel(), cfg.debugCategories());
w.show();
#ifdef _WIN32
SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
#endif
return app.exec();
}

5
tools/chatgui/transport/utun_node.cpp

@ -44,6 +44,11 @@ static void signal_handler(int sig) {
if (g_signal_ua) uasync_wakeup(g_signal_ua);
}
extern "C" void utun_node_signal_shutdown(void) {
g_shutdown = 1;
if (g_signal_ua) uasync_wakeup(g_signal_ua);
}
UtunNode::UtunNode(QObject* parent) : QObject(parent) {}
UtunNode::~UtunNode() {

Loading…
Cancel
Save