Commit 4e732051 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(App): quit properly on SIGINT

parent 485a9f3e
...@@ -72,6 +72,8 @@ public: ...@@ -72,6 +72,8 @@ public:
bool hasFocus () const; bool hasFocus () const;
void quit () override;
static App *getInstance () { static App *getInstance () {
return static_cast<App *>(QApplication::instance()); return static_cast<App *>(QApplication::instance());
} }
...@@ -85,9 +87,6 @@ public: ...@@ -85,9 +87,6 @@ public:
Q_INVOKABLE static void smartShowWindow (QQuickWindow *window); Q_INVOKABLE static void smartShowWindow (QQuickWindow *window);
public slots:
void quit ();
signals: signals:
void configLocaleChanged (const QString &locale); void configLocaleChanged (const QString &locale);
......
...@@ -251,16 +251,16 @@ void SingleApplicationPrivate::connectToPrimary (int msecs, char connectionType) ...@@ -251,16 +251,16 @@ void SingleApplicationPrivate::connectToPrimary (int msecs, char connectionType)
} }
void SingleApplicationPrivate::terminate (int signum) { void SingleApplicationPrivate::terminate (int signum) {
if (signum == SIGINT) {
SingleApplication::instance()->quit();
return;
}
while (!sharedMem.empty()) { while (!sharedMem.empty()) {
delete sharedMem.back(); delete sharedMem.back();
sharedMem.pop_back(); sharedMem.pop_back();
} }
cout << "[PROCESS ABNORMALLY TERMINATED]: " << signum << endl;
#ifdef Q_OS_LINUX
cout << "If you have used valgrind, please remove your ~/.ICEauthority file and rerun." << endl;
#endif // ifdef Q_OS_UNIX
::exit(128 + signum); ::exit(128 + signum);
} }
...@@ -453,3 +453,7 @@ bool SingleApplication::sendMessage (QByteArray message, int timeout) { ...@@ -453,3 +453,7 @@ bool SingleApplication::sendMessage (QByteArray message, int timeout) {
d->socket->waitForBytesWritten(timeout); d->socket->waitForBytesWritten(timeout);
return dataWritten; return dataWritten;
} }
void SingleApplication::quit () {
QCoreApplication::quit();
}
...@@ -112,6 +112,8 @@ public: ...@@ -112,6 +112,8 @@ public:
*/ */
bool sendMessage (QByteArray message, int timeout = 100); bool sendMessage (QByteArray message, int timeout = 100);
virtual void quit ();
Q_SIGNALS: Q_SIGNALS:
void instanceStarted (); void instanceStarted ();
void receivedMessage (quint32 instanceId, QByteArray message); void receivedMessage (quint32 instanceId, QByteArray message);
......
...@@ -119,3 +119,7 @@ void SingleApplicationPrivate::messageReceived (quint32 instanceId, QByteArray m ...@@ -119,3 +119,7 @@ void SingleApplicationPrivate::messageReceived (quint32 instanceId, QByteArray m
Q_Q(SingleApplication); Q_Q(SingleApplication);
Q_EMIT q->receivedMessage(instanceId, message); Q_EMIT q->receivedMessage(instanceId, message);
} }
void SingleApplication::quit () {
QCoreApplication::quit();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment