chatgui: add SetConsoleCtrlHandler for reliable Ctrl-C on Windows
This commit is contained in:
1 parent
a7ec45c4af
commit
faddbef32a
2 files changed
+24
No files matched your search
@@ -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();
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user