mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #2383 from antis81:ngf/fix/ipc
This commit is contained in:
commit
69380d5159
14
src/ipc.cpp
14
src/ipc.cpp
|
@ -19,8 +19,9 @@
|
|||
|
||||
#include "src/ipc.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include <QDebug>
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QThread>
|
||||
#include <random>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -185,12 +186,13 @@ bool IPC::waitUntilAccepted(time_t postTime, int32_t timeout/*=-1*/)
|
|||
{
|
||||
bool result = false;
|
||||
time_t start = time(0);
|
||||
while (!(result = isEventAccepted(postTime)))
|
||||
{
|
||||
qApp->processEvents();
|
||||
QThread::msleep(10);
|
||||
if (timeout > 0 && difftime(time(0), start) >= timeout)
|
||||
forever {
|
||||
result = isEventAccepted(postTime);
|
||||
if (result || (timeout > 0 && difftime(time(0), start) >= timeout))
|
||||
break;
|
||||
|
||||
qApp->processEvents();
|
||||
QThread::msleep(0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
11
src/ipc.h
11
src/ipc.h
|
@ -21,20 +21,19 @@
|
|||
#ifndef IPC_H
|
||||
#define IPC_H
|
||||
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QSharedMemory>
|
||||
#include <QTimer>
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QVector>
|
||||
#include <QMap>
|
||||
#include <functional>
|
||||
#include <ctime>
|
||||
|
||||
using IPCEventHandler = std::function<bool (const QByteArray&)>;
|
||||
|
||||
#define IPC_PROTOCOL_VERSION "2"
|
||||
|
||||
class IPC : public QThread
|
||||
class IPC : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
IPC();
|
||||
|
|
14
src/main.cpp
14
src/main.cpp
|
@ -113,7 +113,7 @@ int main(int argc, char *argv[])
|
|||
parser.process(a);
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
IPC::getInstance();
|
||||
IPC& ipc = IPC::getInstance();
|
||||
#endif
|
||||
|
||||
sodium_init(); // For the auto-updater
|
||||
|
@ -157,7 +157,6 @@ int main(int argc, char *argv[])
|
|||
|
||||
#ifndef Q_OS_ANDROID
|
||||
// Inter-process communication
|
||||
IPC& ipc = IPC::getInstance();
|
||||
ipc.registerEventHandler("uri", &toxURIEventHandler);
|
||||
ipc.registerEventHandler("save", &toxSaveEventHandler);
|
||||
ipc.registerEventHandler("activate", &toxActivateEventHandler);
|
||||
|
@ -233,15 +232,10 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
else if (!ipc.isCurrentOwner() && !parser.isSet("p"))
|
||||
{
|
||||
uint32_t dest = 0;
|
||||
if (parser.isSet("p"))
|
||||
dest = Settings::getInstance().getCurrentProfileId();
|
||||
|
||||
time_t event = ipc.postEvent("activate", QByteArray(), dest);
|
||||
if (ipc.waitUntilAccepted(event, 2))
|
||||
time_t event = ipc.postEvent("activate");
|
||||
if (!ipc.waitUntilAccepted(event, 2))
|
||||
{
|
||||
if (!ipc.isCurrentOwner())
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user