Skip to content

Commit

Permalink
Add more debugging for singleapplication handling
Browse files Browse the repository at this point in the history
See #541
  • Loading branch information
dail8859 committed Apr 7, 2024
1 parent c6a67c3 commit 22a9590
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/NotepadNext/NotepadNextApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/NotepadNext/NotepadNextApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class NotepadNextApplication : public SingleApplication

private slots:
void saveSettings();
void receiveInfoFromSecondaryInstance(quint32 instanceId, QByteArray message);

private:
void openFiles(const QStringList &files);
Expand Down

0 comments on commit 22a9590

Please sign in to comment.