mirror of
https://invent.kde.org/marcoa/a-la-karte.git
synced 2026-03-26 17:03:08 +00:00
gamecenter: detach running processes on shutdown
This commit is contained in:
parent
144076675c
commit
2285de6b1e
2 changed files with 49 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "gamecenterdaemon.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusArgument>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusConnectionInterface>
|
||||
|
|
@ -878,6 +879,47 @@ GameCenterDaemon::GameCenterDaemon(QObject *parent)
|
|||
{
|
||||
}
|
||||
|
||||
GameCenterDaemon::~GameCenterDaemon()
|
||||
{
|
||||
prepareForShutdown();
|
||||
}
|
||||
|
||||
void GameCenterDaemon::prepareForShutdown()
|
||||
{
|
||||
for (auto it = m_sessions.begin(); it != m_sessions.end(); ++it) {
|
||||
if (it.value().scanner) {
|
||||
it.value().scanner->cancel();
|
||||
}
|
||||
|
||||
QPointer<QProcess> proc = it.value().process;
|
||||
it.value().process = nullptr;
|
||||
if (proc) {
|
||||
proc->disconnect(this);
|
||||
if (proc->state() != QProcess::NotRunning) {
|
||||
proc->setParent(nullptr);
|
||||
} else {
|
||||
proc->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
if (it.value().scanner) {
|
||||
it.value().scanner->disconnect(this);
|
||||
it.value().scanner->deleteLater();
|
||||
it.value().scanner = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = m_unitPathWatchers.begin(); it != m_unitPathWatchers.end(); ++it) {
|
||||
if (QObject *watcher = it.value()) {
|
||||
watcher->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
m_unitPathWatchers.clear();
|
||||
m_unitPathToSessionId.clear();
|
||||
m_unitNameToSessionId.clear();
|
||||
}
|
||||
|
||||
bool GameCenterDaemon::init()
|
||||
{
|
||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||
|
|
@ -897,6 +939,10 @@ bool GameCenterDaemon::init()
|
|||
|
||||
recoverExistingSessions();
|
||||
|
||||
if (QCoreApplication::instance()) {
|
||||
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &GameCenterDaemon::prepareForShutdown);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ class GameCenterDaemon : public QObject
|
|||
|
||||
public:
|
||||
explicit GameCenterDaemon(QObject *parent = nullptr);
|
||||
~GameCenterDaemon() override;
|
||||
|
||||
bool init();
|
||||
|
||||
|
|
@ -76,6 +77,8 @@ private:
|
|||
void handleSystemdUnitPropertiesChanged(const QDBusObjectPath &unitPath, const QVariantMap &changedProperties);
|
||||
void removeSessionInternal(const QString &sessionId, const QString &finalState);
|
||||
|
||||
void prepareForShutdown();
|
||||
|
||||
private Q_SLOTS:
|
||||
void handleSystemdUnitNew(const QString &unitName, const QDBusObjectPath &unitPath);
|
||||
void handleSystemdUnitRemoved(const QString &unitName, const QDBusObjectPath &unitPath);
|
||||
|
|
|
|||
Loading…
Reference in a new issue