Merge pull request #3034 from PrismLauncher/backport-3010-to-release-9.x
This commit is contained in:
commit
0f5eb03839
@ -48,6 +48,7 @@
|
|||||||
#include "net/PasteUpload.h"
|
#include "net/PasteUpload.h"
|
||||||
#include "pathmatcher/MultiMatcher.h"
|
#include "pathmatcher/MultiMatcher.h"
|
||||||
#include "pathmatcher/SimplePrefixMatcher.h"
|
#include "pathmatcher/SimplePrefixMatcher.h"
|
||||||
|
#include "tasks/Task.h"
|
||||||
#include "tools/GenericProfiler.h"
|
#include "tools/GenericProfiler.h"
|
||||||
#include "ui/InstanceWindow.h"
|
#include "ui/InstanceWindow.h"
|
||||||
#include "ui/MainWindow.h"
|
#include "ui/MainWindow.h"
|
||||||
@ -1380,6 +1381,7 @@ bool Application::launch(InstancePtr instance, bool online, bool demo, Minecraft
|
|||||||
if (m_updateRunning) {
|
if (m_updateRunning) {
|
||||||
qDebug() << "Cannot launch instances while an update is running. Please try again when updates are completed.";
|
qDebug() << "Cannot launch instances while an update is running. Please try again when updates are completed.";
|
||||||
} else if (instance->canLaunch()) {
|
} else if (instance->canLaunch()) {
|
||||||
|
QMutexLocker locker(&m_instanceExtrasMutex);
|
||||||
auto& extras = m_instanceExtras[instance->id()];
|
auto& extras = m_instanceExtras[instance->id()];
|
||||||
auto window = extras.window;
|
auto window = extras.window;
|
||||||
if (window) {
|
if (window) {
|
||||||
@ -1404,7 +1406,7 @@ bool Application::launch(InstancePtr instance, bool online, bool demo, Minecraft
|
|||||||
connect(controller.get(), &LaunchController::failed, this, &Application::controllerFailed);
|
connect(controller.get(), &LaunchController::failed, this, &Application::controllerFailed);
|
||||||
connect(controller.get(), &LaunchController::aborted, this, [this] { controllerFailed(tr("Aborted")); });
|
connect(controller.get(), &LaunchController::aborted, this, [this] { controllerFailed(tr("Aborted")); });
|
||||||
addRunningInstance();
|
addRunningInstance();
|
||||||
controller->start();
|
QMetaObject::invokeMethod(controller.get(), &Task::start, Qt::QueuedConnection);
|
||||||
return true;
|
return true;
|
||||||
} else if (instance->isRunning()) {
|
} else if (instance->isRunning()) {
|
||||||
showInstanceWindow(instance, "console");
|
showInstanceWindow(instance, "console");
|
||||||
@ -1422,9 +1424,11 @@ bool Application::kill(InstancePtr instance)
|
|||||||
qWarning() << "Attempted to kill instance" << instance->id() << ", which isn't running.";
|
qWarning() << "Attempted to kill instance" << instance->id() << ", which isn't running.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
QMutexLocker locker(&m_instanceExtrasMutex);
|
||||||
auto& extras = m_instanceExtras[instance->id()];
|
auto& extras = m_instanceExtras[instance->id()];
|
||||||
// NOTE: copy of the shared pointer keeps it alive
|
// NOTE: copy of the shared pointer keeps it alive
|
||||||
auto controller = extras.controller;
|
auto controller = extras.controller;
|
||||||
|
locker.unlock();
|
||||||
if (controller) {
|
if (controller) {
|
||||||
return controller->abort();
|
return controller->abort();
|
||||||
}
|
}
|
||||||
@ -1478,6 +1482,8 @@ void Application::controllerSucceeded()
|
|||||||
if (!controller)
|
if (!controller)
|
||||||
return;
|
return;
|
||||||
auto id = controller->id();
|
auto id = controller->id();
|
||||||
|
|
||||||
|
QMutexLocker locker(&m_instanceExtrasMutex);
|
||||||
auto& extras = m_instanceExtras[id];
|
auto& extras = m_instanceExtras[id];
|
||||||
|
|
||||||
// on success, do...
|
// on success, do...
|
||||||
@ -1503,6 +1509,7 @@ void Application::controllerFailed(const QString& error)
|
|||||||
if (!controller)
|
if (!controller)
|
||||||
return;
|
return;
|
||||||
auto id = controller->id();
|
auto id = controller->id();
|
||||||
|
QMutexLocker locker(&m_instanceExtrasMutex);
|
||||||
auto& extras = m_instanceExtras[id];
|
auto& extras = m_instanceExtras[id];
|
||||||
|
|
||||||
// on failure, do... nothing
|
// on failure, do... nothing
|
||||||
@ -1560,6 +1567,7 @@ InstanceWindow* Application::showInstanceWindow(InstancePtr instance, QString pa
|
|||||||
if (!instance)
|
if (!instance)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
auto id = instance->id();
|
auto id = instance->id();
|
||||||
|
QMutexLocker locker(&m_instanceExtrasMutex);
|
||||||
auto& extras = m_instanceExtras[id];
|
auto& extras = m_instanceExtras[id];
|
||||||
auto& window = extras.window;
|
auto& window = extras.window;
|
||||||
|
|
||||||
@ -1597,6 +1605,7 @@ void Application::on_windowClose()
|
|||||||
m_openWindows--;
|
m_openWindows--;
|
||||||
auto instWindow = qobject_cast<InstanceWindow*>(QObject::sender());
|
auto instWindow = qobject_cast<InstanceWindow*>(QObject::sender());
|
||||||
if (instWindow) {
|
if (instWindow) {
|
||||||
|
QMutexLocker locker(&m_instanceExtrasMutex);
|
||||||
auto& extras = m_instanceExtras[instWindow->instanceId()];
|
auto& extras = m_instanceExtras[instWindow->instanceId()];
|
||||||
extras.window = nullptr;
|
extras.window = nullptr;
|
||||||
if (extras.controller) {
|
if (extras.controller) {
|
||||||
|
@ -279,6 +279,7 @@ class Application : public QApplication {
|
|||||||
shared_qobject_ptr<LaunchController> controller;
|
shared_qobject_ptr<LaunchController> controller;
|
||||||
};
|
};
|
||||||
std::map<QString, InstanceXtras> m_instanceExtras;
|
std::map<QString, InstanceXtras> m_instanceExtras;
|
||||||
|
mutable QMutex m_instanceExtrasMutex;
|
||||||
|
|
||||||
// main state variables
|
// main state variables
|
||||||
size_t m_openWindows = 0;
|
size_t m_openWindows = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user