mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-24 12:08:50 +03:00
32 lines
588 B
C
32 lines
588 B
C
|
#pragma once
|
||
|
|
||
|
//
|
||
|
// Taken from
|
||
|
// https://stackoverflow.com/questions/5006547/qt-best-practice-for-a-single-instance-app-protection
|
||
|
//
|
||
|
|
||
|
#include <QObject>
|
||
|
#include <QSharedMemory>
|
||
|
#include <QSystemSemaphore>
|
||
|
|
||
|
class RunGuard
|
||
|
{
|
||
|
public:
|
||
|
RunGuard(const QString &key);
|
||
|
~RunGuard();
|
||
|
|
||
|
bool isAnotherRunning();
|
||
|
bool tryToRun();
|
||
|
void release();
|
||
|
|
||
|
private:
|
||
|
const QString key;
|
||
|
const QString memLockKey;
|
||
|
const QString sharedmemKey;
|
||
|
|
||
|
QSharedMemory sharedMem;
|
||
|
QSystemSemaphore memLock;
|
||
|
|
||
|
Q_DISABLE_COPY(RunGuard)
|
||
|
};
|