mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
fix shutdown
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "ui/mainwindow.h"
|
||||
|
||||
#include <csignal>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QTranslator>
|
||||
@@ -13,6 +15,13 @@
|
||||
#include "sys/windows/MiniDump.h"
|
||||
#endif
|
||||
|
||||
void signal_handler(int signum) {
|
||||
if (qApp) {
|
||||
GetMainWindow()->on_commitDataRequest();
|
||||
qApp->exit();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// Core dump
|
||||
#ifdef Q_OS_WIN
|
||||
@@ -120,6 +129,10 @@ int main(int argc, char *argv[]) {
|
||||
QCoreApplication::installTranslator(&trans_qt);
|
||||
}
|
||||
|
||||
//Signals
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
MainWindow w;
|
||||
return QApplication::exec();
|
||||
}
|
||||
|
||||
@@ -425,6 +425,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
}
|
||||
}
|
||||
|
||||
connect(qApp, &QGuiApplication::commitDataRequest, this, &MainWindow::on_commitDataRequest);
|
||||
|
||||
if (!NekoRay::dataStore->start_minimal) show();
|
||||
}
|
||||
|
||||
@@ -538,11 +540,8 @@ void MainWindow::on_menu_hotkey_settings_triggered() {
|
||||
USE_DIALOG(DialogHotkey)
|
||||
}
|
||||
|
||||
void MainWindow::on_menu_exit_triggered() {
|
||||
neko_set_spmode(NekoRay::SystemProxyMode::DISABLE, false);
|
||||
if (title_spmode == NekoRay::SystemProxyMode::VPN) return;
|
||||
RegisterHotkey(true);
|
||||
|
||||
void MainWindow::on_commitDataRequest() {
|
||||
qDebug() << "Start of data save";
|
||||
if (!isMaximized()) {
|
||||
auto olds = NekoRay::dataStore->mw_size;
|
||||
auto news = QString("%1x%2").arg(size().width()).arg(size().height());
|
||||
@@ -551,17 +550,26 @@ void MainWindow::on_menu_exit_triggered() {
|
||||
NekoRay::dataStore->Save();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
auto last_id = NekoRay::dataStore->started_id;
|
||||
neko_stop();
|
||||
if (NekoRay::dataStore->remember_enable && last_id >= 0) {
|
||||
NekoRay::dataStore->UpdateStartedId(last_id);
|
||||
}
|
||||
qDebug() << "End of data save";
|
||||
}
|
||||
|
||||
void MainWindow::on_menu_exit_triggered() {
|
||||
neko_set_spmode(NekoRay::SystemProxyMode::DISABLE, false);
|
||||
if (title_spmode == NekoRay::SystemProxyMode::VPN) return;
|
||||
RegisterHotkey(true);
|
||||
//
|
||||
on_commitDataRequest();
|
||||
//
|
||||
core_process_killed = true;
|
||||
hide();
|
||||
ExitNekorayCore();
|
||||
|
||||
//
|
||||
if (exit_update) {
|
||||
QDir::setCurrent(QApplication::applicationDirPath());
|
||||
QProcess::startDetached("./updater", QStringList{});
|
||||
|
||||
@@ -58,6 +58,8 @@ signals:
|
||||
|
||||
public slots:
|
||||
|
||||
void on_commitDataRequest();
|
||||
|
||||
void on_menu_exit_triggered();
|
||||
|
||||
private slots:
|
||||
|
||||
Reference in New Issue
Block a user