summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-11-06 21:58:54 +0100
committerPetr Mrázek <peterix@gmail.com>2016-11-06 21:58:54 +0100
commit8b952b387041341f556edcf0bb34576a2fc88568 (patch)
tree804b8976355ef3950628647370e7dfc1bdf96b4f /application
parent37cc59c04d0573a42d67242135495c0a0729f965 (diff)
downloadMultiMC-8b952b387041341f556edcf0bb34576a2fc88568.tar
MultiMC-8b952b387041341f556edcf0bb34576a2fc88568.tar.gz
MultiMC-8b952b387041341f556edcf0bb34576a2fc88568.tar.lz
MultiMC-8b952b387041341f556edcf0bb34576a2fc88568.tar.xz
MultiMC-8b952b387041341f556edcf0bb34576a2fc88568.zip
NOISSUE Refactor and sanitize MultiMC startup/shutdown
* Always create main window. * Properly handle netowrk manager - it was created twice, leading to potential crashes.
Diffstat (limited to 'application')
-rw-r--r--application/MultiMC.cpp40
-rw-r--r--application/MultiMC.h4
-rw-r--r--application/WonkoGui.h3
-rw-r--r--application/main.cpp25
4 files changed, 49 insertions, 23 deletions
diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp
index 40a11a26..c6ac2b63 100644
--- a/application/MultiMC.cpp
+++ b/application/MultiMC.cpp
@@ -286,12 +286,17 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
auto inst = instances()->getInstanceById(m_instanceIdToLaunch);
if(inst)
{
- minecraftlist();
+ // minimized main window
+ showMainWindow(true);
launch(inst, true, nullptr);
return;
}
}
- showMainWindow();
+ if(!m_mainWindow)
+ {
+ // normal main window
+ showMainWindow(false);
+ }
}
MultiMC::~MultiMC()
@@ -340,9 +345,6 @@ void MultiMC::initNetwork()
// init the http meta cache
ENV.initHttpMetaCache();
- // create the global network manager
- ENV.m_qnam.reset(new QNetworkAccessManager(this));
-
// init proxy settings
{
QString proxyTypeStr = settings()->get("ProxyType").toString();
@@ -1052,7 +1054,6 @@ void MultiMC::onExit()
{
// m_instances->saveGroupList();
}
- ENV.destroy();
if(logFile)
{
logFile->flush();
@@ -1126,6 +1127,12 @@ void MultiMC::controllerSucceeded()
}
}
extras.controller.reset();
+ // quit when there are no more windows.
+ if(m_openWindows == 0)
+ {
+ m_status = Status::Succeeded;
+ quit();
+ }
}
void MultiMC::controllerFailed(const QString& error)
@@ -1139,9 +1146,15 @@ void MultiMC::controllerFailed(const QString& error)
// on failure, do... nothing
extras.controller.reset();
+ // quit when there are no more windows.
+ if(m_openWindows == 0)
+ {
+ m_status = Status::Failed;
+ quit();
+ }
}
-MainWindow * MultiMC::showMainWindow()
+MainWindow* MultiMC::showMainWindow(bool minimized)
{
if(m_mainWindow)
{
@@ -1154,9 +1167,18 @@ MainWindow * MultiMC::showMainWindow()
m_mainWindow = new MainWindow();
m_mainWindow->restoreState(QByteArray::fromBase64(MMC->settings()->get("MainWindowState").toByteArray()));
m_mainWindow->restoreGeometry(QByteArray::fromBase64(MMC->settings()->get("MainWindowGeometry").toByteArray()));
- m_mainWindow->show();
+ if(minimized)
+ {
+ m_mainWindow->showMinimized();
+ }
+ else
+ {
+ m_mainWindow->show();
+ }
+
m_mainWindow->checkSetDefaultJava();
m_mainWindow->checkInstancePathForProblems();
+ m_openWindows++;
}
return m_mainWindow;
}
@@ -1177,13 +1199,13 @@ InstanceWindow *MultiMC::showInstanceWindow(InstancePtr instance, QString page)
else
{
window = new InstanceWindow(instance);
+ m_openWindows ++;
connect(window, &InstanceWindow::isClosing, this, &MultiMC::on_windowClose);
}
if(!page.isEmpty())
{
window->selectPage(page);
}
- m_openWindows ++;
if(extras.controller)
{
extras.controller->setParentWidget(window);
diff --git a/application/MultiMC.h b/application/MultiMC.h
index 4deb95d1..7f45e873 100644
--- a/application/MultiMC.h
+++ b/application/MultiMC.h
@@ -142,7 +142,9 @@ public:
bool openJsonEditor(const QString &filename);
InstanceWindow *showInstanceWindow(InstancePtr instance, QString page = QString());
- MainWindow *showMainWindow();
+ MainWindow *showMainWindow(bool minimized = false);
+
+public slots:
void launch(InstancePtr instance, bool online = true, BaseProfilerFactory *profiler = nullptr);
private slots:
diff --git a/application/WonkoGui.h b/application/WonkoGui.h
index 2b87b819..ad0bee89 100644
--- a/application/WonkoGui.h
+++ b/application/WonkoGui.h
@@ -1,11 +1,12 @@
#pragma once
#include <memory>
+#include "QObjectPtr.h"
class QWidget;
class QString;
-using WonkoIndexPtr = std::shared_ptr<class WonkoIndex>;
+using WonkoIndexPtr = shared_qobject_ptr<class WonkoIndex>;
using WonkoVersionListPtr = std::shared_ptr<class WonkoVersionList>;
using WonkoVersionPtr = std::shared_ptr<class WonkoVersion>;
diff --git a/application/main.cpp b/application/main.cpp
index fde5eba7..5b557170 100644
--- a/application/main.cpp
+++ b/application/main.cpp
@@ -9,22 +9,23 @@ int main(int argc, char *argv[])
// initialize Qt
MultiMC app(argc, argv);
- Q_INIT_RESOURCE(instances);
- Q_INIT_RESOURCE(multimc);
- Q_INIT_RESOURCE(backgrounds);
- Q_INIT_RESOURCE(versions);
-
- Q_INIT_RESOURCE(pe_dark);
- Q_INIT_RESOURCE(pe_light);
- Q_INIT_RESOURCE(pe_blue);
- Q_INIT_RESOURCE(pe_colored);
- Q_INIT_RESOURCE(OSX);
- Q_INIT_RESOURCE(iOS);
-
switch (app.status())
{
case MultiMC::Initialized:
+ {
+ Q_INIT_RESOURCE(instances);
+ Q_INIT_RESOURCE(multimc);
+ Q_INIT_RESOURCE(backgrounds);
+ Q_INIT_RESOURCE(versions);
+
+ Q_INIT_RESOURCE(pe_dark);
+ Q_INIT_RESOURCE(pe_light);
+ Q_INIT_RESOURCE(pe_blue);
+ Q_INIT_RESOURCE(pe_colored);
+ Q_INIT_RESOURCE(OSX);
+ Q_INIT_RESOURCE(iOS);
return app.exec();
+ }
case MultiMC::Failed:
return 1;
case MultiMC::Succeeded: