diff --git a/src/ipc.cpp b/src/ipc.cpp index 1c71d1f29..b8ab7cd6b 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -19,8 +19,9 @@ #include "src/ipc.h" #include "src/persistence/settings.h" -#include #include +#include +#include #include #include @@ -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; } diff --git a/src/ipc.h b/src/ipc.h index 736343332..325579f88 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -21,20 +21,19 @@ #ifndef IPC_H #define IPC_H +#include +#include +#include +#include #include #include -#include -#include #include -#include -#include -#include using IPCEventHandler = std::function; #define IPC_PROTOCOL_VERSION "2" -class IPC : public QThread +class IPC : public QObject { Q_OBJECT IPC(); diff --git a/src/main.cpp b/src/main.cpp index b564c5425..3181e3683 100644 --- a/src/main.cpp +++ b/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