summaryrefslogtreecommitdiff
path: root/src/moapplication.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2021-01-11 01:25:47 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2021-01-18 08:20:08 -0500
commit09eb507ddad0d164a39d72c5c121d332966ef462 (patch)
tree4cdc6c84b1322e2e702d303dd92a8e58d09bade2 /src/moapplication.cpp
parent7e8018481284ff9ac1915425e9ed94d532ab33db (diff)
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)
Diffstat (limited to 'src/moapplication.cpp')
-rw-r--r--src/moapplication.cpp49
1 files changed, 44 insertions, 5 deletions
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 <http://www.gnu.org/licenses/>.
#include "tutorialmanager.h"
#include "sanitychecks.h"
#include "mainwindow.h"
+#include "messagedialog.h"
#include "shared/error_report.h"
#include "shared/util.h"
#include <iplugingame.h>
@@ -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<Instance> MOApplication::getCurrentInstance()
{
auto& m = InstanceManager::singleton();