Skip to content

Commit

Permalink
Fix sending message to other instance
Browse files Browse the repository at this point in the history
  • Loading branch information
drfiemost committed Apr 17, 2021
1 parent f7b82c2 commit 7db03be
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/singleApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
#include "utils.h"
#include "xdg.h"

#ifdef _WIN32
# include <windows.h>
#endif

#include <QDir>
#include <QDebug>

Expand All @@ -39,7 +35,7 @@ singleApp::singleApp(int & argc, char ** argv) :
bool singleApp::isRunning()
{
#ifdef _WIN32
const QString fifoFileName("\\\\.\\pipe\\musiqt.fifo");
const QString fifoFileName(R"(\\.\pipe\musiqt.fifo)");
#else
const QString fifoFileName(QString("%1/.musiqt.fifo").arg(xdg::getRuntimeDir()));
#endif
Expand Down Expand Up @@ -90,6 +86,7 @@ bool singleApp::isRunning()
qint64 res = socket.write(block);
qDebug() << "res: " << res;
socket.flush();
socket.waitForBytesWritten();
socket.disconnectFromServer();
}
else
Expand Down Expand Up @@ -125,17 +122,18 @@ void singleApp::acceptMessage()
return;
}

socket->waitForReadyRead();

qDebug() << "data: " << socket->bytesAvailable();
QDataStream in(socket);
in.setVersion(QDataStream::Qt_4_0);
QString message;
in >> message;
qDebug() << "msg: " << message;
if (socket->waitForReadyRead())
{
qDebug() << "data: " << socket->bytesAvailable();
QDataStream in(socket);
in.setVersion(QDataStream::Qt_4_0);
QString message;
in >> message;
qDebug() << "msg: " << message;

if (!message.isEmpty())
emit sendMessage(message);
if (!message.isEmpty())
emit sendMessage(message);
}

delete socket;
}

0 comments on commit 7db03be

Please sign in to comment.