1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-09-10 12:03:18 +02:00

runguard: enable on linux

GitLab: #350
GitLab: #439
Change-Id: Iba420995401cb4a8c20f3611473eb6f5bd22334b
This commit is contained in:
Sébastien Blin 2021-06-02 10:56:37 -04:00
parent 64720224eb
commit 2d8078a027
2 changed files with 11 additions and 7 deletions

View file

@ -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;
}

View file

@ -52,8 +52,8 @@ private:
QSharedMemory sharedMem_;
QSystemSemaphore memLock_;
QLocalSocket* socket_;
QLocalServer* server_;
QLocalSocket* socket_ {nullptr};
QLocalServer* server_ {nullptr};
Q_DISABLE_COPY(RunGuard)
};