From 381c12547fe91a7392f42337674da390841b39ed Mon Sep 17 00:00:00 2001 From: OverMighty Date: Sun, 9 Feb 2020 16:17:41 +0100 Subject: [PATCH] feat: allow telling the main process to import a zip This commit enhances the IPC message system and adds a new IPC command in order to allow secondary MultiMC processes that were started by executing MultiMC with the `--import` command-line option to tell the main MutliMC process to open the "Import from zip" dialog window and prefill the URL field with the specified URL. --- application/MultiMC.cpp | 44 +++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 45df5937..393ea046 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -284,13 +284,20 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) connect(m_peerInstance, &LocalPeer::messageReceived, this, &MultiMC::messageReceived); if(m_peerInstance->isClient()) { + int timeout = 2000; + if(m_instanceIdToLaunch.isEmpty()) { - m_peerInstance->sendMessage("activate", 2000); + m_peerInstance->sendMessage("activate", timeout); + + if(!m_zipToImport.isEmpty()) + { + m_peerInstance->sendMessage("import " + m_zipToImport.toString(), timeout); + } } else { - m_peerInstance->sendMessage(m_instanceIdToLaunch, 2000); + m_peerInstance->sendMessage("launch " + m_instanceIdToLaunch, timeout); } m_status = MultiMC::Succeeded; return; @@ -820,9 +827,8 @@ void MultiMC::performMainStartupAction() } if(!m_zipToImport.isEmpty()) { - qDebug() << "<> Importing instance from zip:" << m_zipToImport.toString(); - QList urls = { m_zipToImport }; - m_mainWindow->droppedURLs(urls); + qDebug() << "<> Importing instance from zip:" << m_zipToImport; + m_mainWindow->droppedURLs({ m_zipToImport }); } } @@ -860,18 +866,40 @@ void MultiMC::messageReceived(const QString& message) qDebug() << "Received message" << message << "while still initializing. It will be ignored."; return; } - if(message == "activate") + + QStringList args = message.split(' '); + QString command = args.takeFirst(); + + if(command == "activate") { showMainWindow(); } - else + else if(command == "import") { - auto inst = instances()->getInstanceById(message); + if(args.isEmpty()) + { + qWarning() << "Received" << command << "message without a zip path/URL."; + return; + } + m_mainWindow->droppedURLs({ QUrl(args.takeFirst()) }); + } + else if(command == "launch") + { + if(args.isEmpty()) + { + qWarning() << "Received" << command << "message without an instance ID."; + return; + } + auto inst = instances()->getInstanceById(args.takeFirst()); if(inst) { launch(inst, true, nullptr); } } + else + { + qWarning() << "Received invalid message" << message; + } } void MultiMC::analyticsSettingChanged(const Setting&, QVariant value)