diff options
author | OverMighty <its.overmighty@gmail.com> | 2020-02-09 16:17:41 +0100 |
---|---|---|
committer | OverMighty <its.overmighty@gmail.com> | 2020-02-09 16:17:41 +0100 |
commit | 381c12547fe91a7392f42337674da390841b39ed (patch) | |
tree | 9ba46076ac08ab8762e36a3f19a7344f3c66e474 | |
parent | 060d6955e1271bc05e35e5e24b71e1b7b0e8eb17 (diff) | |
download | MultiMC-381c12547fe91a7392f42337674da390841b39ed.tar MultiMC-381c12547fe91a7392f42337674da390841b39ed.tar.gz MultiMC-381c12547fe91a7392f42337674da390841b39ed.tar.lz MultiMC-381c12547fe91a7392f42337674da390841b39ed.tar.xz MultiMC-381c12547fe91a7392f42337674da390841b39ed.zip |
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.
-rw-r--r-- | application/MultiMC.cpp | 44 |
1 files 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<QUrl> 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") + { + if(args.isEmpty()) + { + qWarning() << "Received" << command << "message without a zip path/URL."; + return; + } + m_mainWindow->droppedURLs({ QUrl(args.takeFirst()) }); + } + else if(command == "launch") { - auto inst = instances()->getInstanceById(message); + 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) |