From 22a9590d15c04fb5298476af42ca0079ae1b24cd Mon Sep 17 00:00:00 2001 From: dail8859 Date: Sat, 6 Apr 2024 22:39:51 -0400 Subject: [PATCH] Add more debugging for singleapplication handling See #541 --- src/NotepadNext/NotepadNextApplication.cpp | 40 ++++++++++++++-------- src/NotepadNext/NotepadNextApplication.h | 1 + 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/NotepadNext/NotepadNextApplication.cpp b/src/NotepadNext/NotepadNextApplication.cpp index c16014ccb..3e79b55df 100644 --- a/src/NotepadNext/NotepadNextApplication.cpp +++ b/src/NotepadNext/NotepadNextApplication.cpp @@ -195,20 +195,7 @@ bool NotepadNextApplication::init() }); connect(this, &SingleApplication::instanceStarted, window, &MainWindow::bringWindowToForeground); - - connect(this, &SingleApplication::receivedMessage, this, [&](quint32 instanceId, QByteArray message) { - Q_UNUSED(instanceId) - - QDataStream stream(&message, QIODevice::ReadOnly); - QStringList args; - - stream >> args; - - QCommandLineParser parser; - parseCommandLine(parser, args); - - openFiles(parser.positionalArguments()); - }, Qt::QueuedConnection); + connect(this, &SingleApplication::receivedMessage, this, &NotepadNextApplication::receiveInfoFromSecondaryInstance, Qt::QueuedConnection); connect(this, &NotepadNextApplication::applicationStateChanged, this, [&](Qt::ApplicationState state) { if (state == Qt::ApplicationActive) { @@ -420,11 +407,34 @@ QString NotepadNextApplication::detectLanguageFromContents(ScintillaNext *editor void NotepadNextApplication::sendInfoToPrimaryInstance() { + qInfo(Q_FUNC_INFO); + QByteArray buffer; QDataStream stream(&buffer, QIODevice::WriteOnly); stream << arguments(); - sendMessage(buffer); + const bool success = sendMessage(buffer); + + if (!success) { + qWarning("sendMessage() unsuccessful"); + } +} + +void NotepadNextApplication::receiveInfoFromSecondaryInstance(quint32 instanceId, QByteArray message) +{ + qInfo(Q_FUNC_INFO); + + Q_UNUSED(instanceId) + + QDataStream stream(&message, QIODevice::ReadOnly); + QStringList args; + + stream >> args; + + QCommandLineParser parser; + parseCommandLine(parser, args); + + openFiles(parser.positionalArguments()); } bool NotepadNextApplication::isRunningAsAdmin() const diff --git a/src/NotepadNext/NotepadNextApplication.h b/src/NotepadNext/NotepadNextApplication.h index 833981115..b4b4aee54 100644 --- a/src/NotepadNext/NotepadNextApplication.h +++ b/src/NotepadNext/NotepadNextApplication.h @@ -72,6 +72,7 @@ class NotepadNextApplication : public SingleApplication private slots: void saveSettings(); + void receiveInfoFromSecondaryInstance(quint32 instanceId, QByteArray message); private: void openFiles(const QStringList &files);