LaunchController: fix double task finish (#5301)

This commit is contained in:
Alexandru Ionut Tripon 2026-04-03 20:37:39 +00:00 committed by GitHub
commit 447333c3f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 33 deletions

View file

@ -50,7 +50,7 @@
#include <QInputDialog> #include <QInputDialog>
#include <QList> #include <QList>
#include <QPushButton> #include <QPushButton>
#include <QRegularExpression> #include <utility>
#include "BuildConfig.h" #include "BuildConfig.h"
#include "JavaCommon.h" #include "JavaCommon.h"
@ -82,9 +82,9 @@ void LaunchController::decideAccount()
} }
// Select the account to use. If the instance has a specific account set, that will be used. Otherwise, the default account will be used // Select the account to use. If the instance has a specific account set, that will be used. Otherwise, the default account will be used
auto accounts = APPLICATION->accounts(); auto* accounts = APPLICATION->accounts();
auto instanceAccountId = m_instance->settings()->get("InstanceAccountId").toString(); const auto instanceAccountId = m_instance->settings()->get("InstanceAccountId").toString();
auto instanceAccountIndex = accounts->findAccountByProfileId(instanceAccountId); const auto instanceAccountIndex = accounts->findAccountByProfileId(instanceAccountId);
if (instanceAccountIndex == -1 || instanceAccountId.isEmpty()) { if (instanceAccountIndex == -1 || instanceAccountId.isEmpty()) {
m_accountToUse = accounts->defaultAccount(); m_accountToUse = accounts->defaultAccount();
} else { } else {
@ -141,7 +141,7 @@ LaunchDecision LaunchController::decideLaunchMode()
} }
} }
const auto accounts = APPLICATION->accounts(); const auto* accounts = APPLICATION->accounts();
MinecraftAccountPtr accountToCheck = nullptr; MinecraftAccountPtr accountToCheck = nullptr;
if (m_accountToUse->accountType() != AccountType::Offline) { if (m_accountToUse->accountType() != AccountType::Offline) {
@ -213,7 +213,7 @@ LaunchDecision LaunchController::decideLaunchMode()
return LaunchDecision::Abort; return LaunchDecision::Abort;
} }
bool LaunchController::askPlayDemo() bool LaunchController::askPlayDemo() const
{ {
QMessageBox box(m_parentWidget); QMessageBox box(m_parentWidget);
box.setWindowTitle(tr("Play demo?")); box.setWindowTitle(tr("Play demo?"));
@ -223,15 +223,15 @@ bool LaunchController::askPlayDemo()
text += tr("\n\nDo you want to play the demo?"); text += tr("\n\nDo you want to play the demo?");
box.setText(text); box.setText(text);
box.setIcon(QMessageBox::Warning); box.setIcon(QMessageBox::Warning);
auto demoButton = box.addButton(tr("Play Demo"), QMessageBox::ButtonRole::YesRole); const auto* demoButton = box.addButton(tr("Play Demo"), QMessageBox::ButtonRole::YesRole);
auto cancelButton = box.addButton(tr("Cancel"), QMessageBox::ButtonRole::NoRole); auto* cancelButton = box.addButton(tr("Cancel"), QMessageBox::ButtonRole::NoRole);
box.setDefaultButton(cancelButton); box.setDefaultButton(cancelButton);
box.exec(); box.exec();
return box.clickedButton() == demoButton; return box.clickedButton() == demoButton;
} }
QString LaunchController::askOfflineName(QString playerName, bool* ok) QString LaunchController::askOfflineName(const QString& playerName, bool* ok) const
{ {
if (ok != nullptr) { if (ok != nullptr) {
*ok = false; *ok = false;
@ -253,7 +253,7 @@ QString LaunchController::askOfflineName(QString playerName, bool* ok)
break; break;
} }
QString lastOfflinePlayerName = APPLICATION->settings()->get("LastOfflinePlayerName").toString(); const QString lastOfflinePlayerName = APPLICATION->settings()->get("LastOfflinePlayerName").toString();
QString usedname = lastOfflinePlayerName.isEmpty() ? playerName : lastOfflinePlayerName; QString usedname = lastOfflinePlayerName.isEmpty() ? playerName : lastOfflinePlayerName;
ChooseOfflineNameDialog dialog(message, m_parentWidget); ChooseOfflineNameDialog dialog(message, m_parentWidget);
@ -331,14 +331,14 @@ void LaunchController::login()
launchInstance(); launchInstance();
} }
bool LaunchController::reauthenticateAccount(MinecraftAccountPtr account, QString reason) bool LaunchController::reauthenticateAccount(const MinecraftAccountPtr& account, const QString& reason)
{ {
auto button = QMessageBox::warning( auto button = QMessageBox::warning(
m_parentWidget, tr("Account refresh failed"), tr("%1. Do you want to reauthenticate this account?").arg(reason), m_parentWidget, tr("Account refresh failed"), tr("%1. Do you want to reauthenticate this account?").arg(reason),
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, QMessageBox::StandardButton::Yes); QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, QMessageBox::StandardButton::Yes);
if (button == QMessageBox::StandardButton::Yes) { if (button == QMessageBox::StandardButton::Yes) {
auto accounts = APPLICATION->accounts(); auto* accounts = APPLICATION->accounts();
bool isDefault = accounts->defaultAccount() == account; const bool isDefault = accounts->defaultAccount() == account;
accounts->removeAccount(accounts->index(accounts->findAccountByProfileId(account->profileId()))); accounts->removeAccount(accounts->index(accounts->findAccountByProfileId(account->profileId())));
if (account->accountType() == AccountType::MSA) { if (account->accountType() == AccountType::MSA) {
auto newAccount = MSALoginDialog::newAccount(m_parentWidget); auto newAccount = MSALoginDialog::newAccount(m_parentWidget);
@ -346,8 +346,9 @@ bool LaunchController::reauthenticateAccount(MinecraftAccountPtr account, QStrin
if (newAccount != nullptr) { if (newAccount != nullptr) {
accounts->addAccount(newAccount); accounts->addAccount(newAccount);
if (isDefault) if (isDefault) {
accounts->setDefaultAccount(newAccount); accounts->setDefaultAccount(newAccount);
}
if (m_accountToUse == account) { if (m_accountToUse == account) {
m_accountToUse = nullptr; m_accountToUse = nullptr;
@ -358,14 +359,13 @@ bool LaunchController::reauthenticateAccount(MinecraftAccountPtr account, QStrin
} }
} }
emitFailed(reason);
return false; return false;
} }
void LaunchController::launchInstance() void LaunchController::launchInstance()
{ {
Q_ASSERT_X(m_instance != NULL, "launchInstance", "instance is NULL"); Q_ASSERT(m_instance != nullptr);
Q_ASSERT_X(m_session.get() != nullptr, "launchInstance", "session is NULL"); Q_ASSERT(m_session.get() != nullptr);
if (!m_instance->reloadSettings()) { if (!m_instance->reloadSettings()) {
QMessageBox::critical(m_parentWidget, tr("Error!"), tr("Couldn't load the instance profile.")); QMessageBox::critical(m_parentWidget, tr("Error!"), tr("Couldn't load the instance profile."));
@ -379,8 +379,8 @@ void LaunchController::launchInstance()
return; return;
} }
auto console = qobject_cast<InstanceWindow*>(m_parentWidget); const auto* console = qobject_cast<InstanceWindow*>(m_parentWidget);
auto showConsole = m_instance->settings()->get("ShowConsole").toBool(); const auto showConsole = m_instance->settings()->get("ShowConsole").toBool();
if (!console && showConsole) { if (!console && showConsole) {
APPLICATION->showInstanceWindow(m_instance); APPLICATION->showInstanceWindow(m_instance);
} }
@ -395,7 +395,7 @@ void LaunchController::launchInstance()
online_mode = "online"; online_mode = "online";
// Prepend Server Status // Prepend Server Status
QStringList servers = { "login.microsoftonline.com", "session.minecraft.net", "textures.minecraft.net", "api.mojang.com" }; const QStringList servers = { "login.microsoftonline.com", "session.minecraft.net", "textures.minecraft.net", "api.mojang.com" };
m_launcher->prependStep(makeShared<PrintServers>(m_launcher, servers)); m_launcher->prependStep(makeShared<PrintServers>(m_launcher, servers));
} else { } else {
@ -465,10 +465,10 @@ void LaunchController::onFailed(QString reason)
if (m_instance->settings()->get("ShowConsoleOnError").toBool()) { if (m_instance->settings()->get("ShowConsoleOnError").toBool()) {
APPLICATION->showInstanceWindow(m_instance, "console"); APPLICATION->showInstanceWindow(m_instance, "console");
} }
emitFailed(reason); emitFailed(std::move(reason));
} }
void LaunchController::onProgressRequested(Task* task) void LaunchController::onProgressRequested(Task* task) const
{ {
ProgressDialog progDialog(m_parentWidget); ProgressDialog progDialog(m_parentWidget);
progDialog.setSkipButton(true, tr("Abort")); progDialog.setSkipButton(true, tr("Abort"));

View file

@ -50,11 +50,11 @@ class LaunchController : public Task {
void executeTask() override; void executeTask() override;
LaunchController(); LaunchController();
virtual ~LaunchController() = default; ~LaunchController() override = default;
void setInstance(BaseInstance* instance) { m_instance = instance; } void setInstance(BaseInstance* instance) { m_instance = instance; }
BaseInstance* instance() { return m_instance; } BaseInstance* instance() const { return m_instance; }
void setLaunchMode(const LaunchMode mode) { m_wantedLaunchMode = mode; } void setLaunchMode(const LaunchMode mode) { m_wantedLaunchMode = mode; }
@ -68,7 +68,7 @@ class LaunchController : public Task {
void setAccountToUse(MinecraftAccountPtr accountToUse) { m_accountToUse = std::move(accountToUse); } void setAccountToUse(MinecraftAccountPtr accountToUse) { m_accountToUse = std::move(accountToUse); }
QString id() { return m_instance->id(); } QString id() const { return m_instance->id(); }
bool abort() override; bool abort() override;
@ -77,27 +77,27 @@ class LaunchController : public Task {
void launchInstance(); void launchInstance();
void decideAccount(); void decideAccount();
LaunchDecision decideLaunchMode(); LaunchDecision decideLaunchMode();
bool askPlayDemo(); bool askPlayDemo() const;
QString askOfflineName(QString playerName, bool* ok = nullptr); QString askOfflineName(const QString& playerName, bool* ok = nullptr) const;
bool reauthenticateAccount(MinecraftAccountPtr account, QString reason); bool reauthenticateAccount(const MinecraftAccountPtr& account, const QString& reason);
private slots: private slots:
void readyForLaunch(); void readyForLaunch();
void onSucceeded(); void onSucceeded();
void onFailed(QString reason); void onFailed(QString reason);
void onProgressRequested(Task* task); void onProgressRequested(Task* task) const;
private: private:
LaunchMode m_wantedLaunchMode = LaunchMode::Normal; LaunchMode m_wantedLaunchMode = LaunchMode::Normal;
LaunchMode m_actualLaunchMode = LaunchMode::Normal; LaunchMode m_actualLaunchMode = LaunchMode::Normal;
BaseProfilerFactory* m_profiler = nullptr; BaseProfilerFactory* m_profiler = nullptr;
QString m_offlineName; QString m_offlineName;
BaseInstance* m_instance; BaseInstance* m_instance = nullptr;
QWidget* m_parentWidget = nullptr; QWidget* m_parentWidget = nullptr;
InstanceWindow* m_console = nullptr; InstanceWindow* m_console = nullptr;
MinecraftAccountPtr m_accountToUse = nullptr; MinecraftAccountPtr m_accountToUse = nullptr;
AuthSessionPtr m_session; AuthSessionPtr m_session = nullptr;
LaunchTask* m_launcher; LaunchTask* m_launcher = nullptr;
MinecraftTarget::Ptr m_targetToJoin; MinecraftTarget::Ptr m_targetToJoin = nullptr;
}; };