From 09eb507ddad0d164a39d72c5c121d332966ef462 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 11 Jan 2021 01:25:47 -0500 Subject: moved externalMessage() to MOApplication commands can forward to the primary instance added reload-plugin command MessageDialog now tries to find the main window when the reference is null, which actually used to happen often because activeWindow() is typically used, but that's null when the main window doesn't have focus (like when downloading from nexus, for example) --- src/moapplication.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'src/moapplication.cpp') diff --git a/src/moapplication.cpp b/src/moapplication.cpp index d1622d59..01d75ad1 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -31,6 +31,7 @@ along with Mod Organizer. If not, see . #include "tutorialmanager.h" #include "sanitychecks.h" #include "mainwindow.h" +#include "messagedialog.h" #include "shared/error_report.h" #include "shared/util.h" #include @@ -175,6 +176,14 @@ OrganizerCore& MOApplication::core() return *m_core; } +void MOApplication::firstTimeSetup(MOMultiProcess& multiProcess) +{ + connect( + &multiProcess, &MOMultiProcess::messageSent, this, + [this](auto&& s){ externalMessage(s); }, + Qt::QueuedConnection); +} + int MOApplication::setup(MOMultiProcess& multiProcess) { TimeThis tt("MOApplication setup()"); @@ -350,11 +359,10 @@ int MOApplication::run(MOMultiProcess& multiProcess) // main window m_nexus->getAccessManager()->setTopLevelWidget(&mainWindow); - QObject::connect(&mainWindow, SIGNAL(styleChanged(QString)), this, - SLOT(setStyleFile(QString))); - - QObject::connect(&multiProcess, SIGNAL(messageSent(QString)), m_core.get(), - SLOT(externalMessage(QString))); + connect( + &mainWindow, &MainWindow::styleChanged, this, + [this](auto&& file){ setStyleFile(file); }, + Qt::QueuedConnection); log::debug("displaying main window"); @@ -377,6 +385,37 @@ int MOApplication::run(MOMultiProcess& multiProcess) return res; } +void MOApplication::externalMessage(const QString& message) +{ + log::debug("received external message '{}'", message); + + MOShortcut moshortcut(message); + + if (moshortcut.isValid()) { + if(moshortcut.hasExecutable()) { + m_core->processRunner() + .setFromShortcut(moshortcut) + .setWaitForCompletion(ProcessRunner::Refresh) + .run(); + } + } else if (isNxmLink(message)) { + MessageDialog::showMessage(tr("Download started"), qApp->activeWindow()); + m_core->downloadRequestedNXM(message); + } else { + cl::CommandLine cl; + + if (auto r=cl.process(message.toStdWString())) { + log::debug( + "while processing external message, command line wants to " + "exit; ignoring"); + + return; + } + + cl.runPostOrganizer(*m_core); + } +} + std::unique_ptr MOApplication::getCurrentInstance() { auto& m = InstanceManager::singleton(); -- cgit v1.3.1