implement gracefull shutdown for macOS

This commit is contained in:
Nova 2025-08-29 21:33:50 +03:30
parent 5fa22bdb87
commit 38bc43c6ad

View File

@ -199,10 +199,6 @@ int main(int argc, char* argv[]) {
QGuiApplication::tr("QT_LAYOUT_DIRECTION"); QGuiApplication::tr("QT_LAYOUT_DIRECTION");
loadTranslate(locale); loadTranslate(locale);
// Signals
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);
// Check if another instance is running // Check if another instance is running
QByteArray hashBytes = QCryptographicHash::hash(wd.absolutePath().toUtf8(), QCryptographicHash::Md5).toBase64(QByteArray::OmitTrailingEquals); QByteArray hashBytes = QCryptographicHash::hash(wd.absolutePath().toUtf8(), QCryptographicHash::Md5).toBase64(QByteArray::OmitTrailingEquals);
hashBytes.replace('+', '0').replace('/', '1'); hashBytes.replace('+', '0').replace('/', '1');
@ -237,11 +233,24 @@ int main(int argc, char* argv[]) {
QLocalServer::removeServer(serverName); QLocalServer::removeServer(serverName);
}); });
#ifdef Q_OS_LINUX
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);
#endif
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
auto eventFilter = new PowerOffTaskkillFilter(signal_handler); auto eventFilter = new PowerOffTaskkillFilter(signal_handler);
a.installNativeEventFilter(eventFilter); a.installNativeEventFilter(eventFilter);
#endif #endif
#ifdef Q_OS_MACOS
QObject::connect(qApp, &QGuiApplication::commitDataRequest, [&](QSessionManager &manager)
{
Q_UNUSED(manager);
signal_handler(0);
});
#endif
UI_InitMainWindow(); UI_InitMainWindow();
return QApplication::exec(); return QApplication::exec();
} }