Skip to content
Snippets Groups Projects
Commit 2d8078a0 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

runguard: enable on linux

GitLab: #350
GitLab: #439
Change-Id: Iba420995401cb4a8c20f3611473eb6f5bd22334b
parent 64720224
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@
#include "mainapplication.h"
#include <QCryptographicHash>
#include <QLocalSocket>
namespace {
......@@ -77,16 +78,16 @@ RunGuard::isAnotherRunning()
bool
RunGuard::tryToRun()
{
#ifdef Q_OS_WIN
if (isAnotherRunning()) {
/*
* This is a secondary instance,
* connect to the primary instance to trigger a restore
* then fail.
*/
if (socket_ == nullptr) {
if (!socket_)
socket_ = new QLocalSocket();
}
if (!socket_)
return false;
if (socket_->state() == QLocalSocket::UnconnectedState
|| socket_->state() == QLocalSocket::ClosingState) {
socket_->connectToServer(key_);
......@@ -94,7 +95,11 @@ RunGuard::tryToRun()
if (socket_->state() == QLocalSocket::ConnectingState) {
socket_->waitForConnected();
}
return false;
if (socket_->state() == QLocalSocket::ConnectedState) {
return false;
}
// If not connected, this means that the server doesn't exists
// and the app can be relaunched (can be the case after a client crash or Ctrl+C)
}
memLock_.acquire();
......@@ -117,7 +122,6 @@ RunGuard::tryToRun()
&QLocalServer::newConnection,
this,
&RunGuard::tryRestorePrimaryInstance);
#endif
return true;
}
......
......@@ -52,8 +52,8 @@ private:
QSharedMemory sharedMem_;
QSystemSemaphore memLock_;
QLocalSocket* socket_;
QLocalServer* server_;
QLocalSocket* socket_ {nullptr};
QLocalServer* server_ {nullptr};
Q_DISABLE_COPY(RunGuard)
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment