mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-20 02:40:20 +08:00
add: added os process signals support
This commit is contained in:
parent
e42c978ad8
commit
2d829d52f9
@ -1 +1 @@
|
|||||||
3154
|
3155
|
||||||
|
27
src/main.cpp
27
src/main.cpp
@ -7,6 +7,7 @@
|
|||||||
#include <QStyleFactory>
|
#include <QStyleFactory>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <singleapplication.h>
|
#include <singleapplication.h>
|
||||||
|
#include <csignal>
|
||||||
#include "w_MainWindow.hpp"
|
#include "w_MainWindow.hpp"
|
||||||
#include "QvCore/QvCommandLineArgs.hpp"
|
#include "QvCore/QvCommandLineArgs.hpp"
|
||||||
|
|
||||||
@ -17,6 +18,20 @@
|
|||||||
|
|
||||||
bool isDebug = false;
|
bool isDebug = false;
|
||||||
|
|
||||||
|
|
||||||
|
void signalHandler(int signum)
|
||||||
|
{
|
||||||
|
cout << "Interrupt signal (" << signum << ") received." << endl;
|
||||||
|
|
||||||
|
if (MainWindow::mwInstance && MainWindow::mwInstance->vinstance) {
|
||||||
|
cout << "Trying to stop connection..." << endl;
|
||||||
|
MainWindow::mwInstance->vinstance->StopConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(signum);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool verifyConfigAvaliability(QString path, bool checkExistingConfig)
|
bool verifyConfigAvaliability(QString path, bool checkExistingConfig)
|
||||||
{
|
{
|
||||||
// Does not exist.
|
// Does not exist.
|
||||||
@ -196,6 +211,12 @@ bool initialiseQv2ray()
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
// Register signal handlers.
|
||||||
|
signal(SIGINT, signalHandler);
|
||||||
|
signal(SIGHUP, signalHandler);
|
||||||
|
signal(SIGKILL, signalHandler);
|
||||||
|
signal(SIGTERM, signalHandler);
|
||||||
|
//
|
||||||
// parse the command line before starting as a Qt application
|
// parse the command line before starting as a Qt application
|
||||||
{
|
{
|
||||||
std::unique_ptr<QCoreApplication> consoleApp(new QCoreApplication(argc, argv));
|
std::unique_ptr<QCoreApplication> consoleApp(new QCoreApplication(argc, argv));
|
||||||
@ -441,6 +462,12 @@ int main(int argc, char *argv[])
|
|||||||
QObject::connect(&_qApp, &QGuiApplication::commitDataRequest, []() {
|
QObject::connect(&_qApp, &QGuiApplication::commitDataRequest, []() {
|
||||||
LOG(MODULE_INIT, "Quit triggered by session manager.");
|
LOG(MODULE_INIT, "Quit triggered by session manager.");
|
||||||
});
|
});
|
||||||
|
signal(SIGUSR1, [](int) {
|
||||||
|
emit MainWindow::mwInstance->Connect();
|
||||||
|
});
|
||||||
|
signal(SIGUSR2, [](int) {
|
||||||
|
emit MainWindow::mwInstance->DisConnect();
|
||||||
|
});
|
||||||
auto rcode = _qApp.exec();
|
auto rcode = _qApp.exec();
|
||||||
LOG(MODULE_INIT, "Quitting normally")
|
LOG(MODULE_INIT, "Quitting normally")
|
||||||
return rcode;
|
return rcode;
|
||||||
|
@ -196,6 +196,7 @@ MainWindow::MainWindow(QWidget *parent):
|
|||||||
// Share options
|
// Share options
|
||||||
connect(action_RCM_ShareQR, &QAction::triggered, this, &MainWindow::on_action_RCM_ShareQR_triggered);
|
connect(action_RCM_ShareQR, &QAction::triggered, this, &MainWindow::on_action_RCM_ShareQR_triggered);
|
||||||
//
|
//
|
||||||
|
// Globally invokable signals.
|
||||||
connect(this, &MainWindow::Connect, this, &MainWindow::on_startButton_clicked);
|
connect(this, &MainWindow::Connect, this, &MainWindow::on_startButton_clicked);
|
||||||
connect(this, &MainWindow::DisConnect, this, &MainWindow::on_stopButton_clicked);
|
connect(this, &MainWindow::DisConnect, this, &MainWindow::on_stopButton_clicked);
|
||||||
connect(this, &MainWindow::ReConnect, this, &MainWindow::on_reconnectButton_clicked);
|
connect(this, &MainWindow::ReConnect, this, &MainWindow::on_reconnectButton_clicked);
|
||||||
|
Loading…
Reference in New Issue
Block a user