mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(ipc): make IPC user specific
This allows multiple users on a system each running qTox to use IPC at once. Fix #6076
This commit is contained in:
parent
d028f9e394
commit
2fe1918083
30
src/ipc.cpp
30
src/ipc.cpp
|
@ -21,9 +21,37 @@
|
|||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QThread>
|
||||
|
||||
#include <ctime>
|
||||
#include <random>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
const char* getCurUsername()
|
||||
{
|
||||
return getenv("USERNAME");
|
||||
}
|
||||
#else
|
||||
const char* getCurUsername()
|
||||
{
|
||||
return getenv("USER");
|
||||
}
|
||||
#endif
|
||||
|
||||
QString getIpcKey()
|
||||
{
|
||||
auto* user = getCurUsername();
|
||||
if (!user)
|
||||
{
|
||||
qWarning() << "Failed to get current username. Will use a global IPC.";
|
||||
user = "";
|
||||
}
|
||||
return QString("qtox-" IPC_PROTOCOL_VERSION "-") + user;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
/**
|
||||
* @var time_t IPC::lastEvent
|
||||
|
@ -40,7 +68,7 @@
|
|||
|
||||
IPC::IPC(uint32_t profileId)
|
||||
: profileId{profileId}
|
||||
, globalMemory{"qtox-" IPC_PROTOCOL_VERSION}
|
||||
, globalMemory{getIpcKey()}
|
||||
{
|
||||
qRegisterMetaType<IPCEventHandler>("IPCEventHandler");
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user