From 02f79be84811c5f9b1b8a3b5096f135353218a54 Mon Sep 17 00:00:00 2001 From: Emma Date: Tue, 22 Aug 2023 11:02:09 -0700 Subject: [PATCH] feat: automatically refresh accounts before launch if they are offline Signed-off-by: Emma --- launcher/LaunchController.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp index b21eb281f..c065ea2c9 100644 --- a/launcher/LaunchController.cpp +++ b/launcher/LaunchController.cpp @@ -168,7 +168,26 @@ void LaunchController::login() switch (m_accountToUse->accountState()) { case AccountState::Offline: { - m_session->wants_online = false; + if (m_accountToUse->accountData()->type == AccountType::Offline) { + m_session->wants_online = false; + } else { + auto accounts = APPLICATION->accounts(); + accounts->requestRefresh(m_accountToUse->internalId()); + + // Wait for the account to refresh + ProgressDialog progDialog(m_parentWidget); + progDialog.setSkipButton(true, tr("Play Offline")); + auto task = m_accountToUse->currentTask(); + progDialog.execWithTask(task.get()); + + // Check if the account is still offline + if (m_accountToUse->accountState() == AccountState::Offline) { + // If so, we fall through to the online case with wants_online set to false + m_session->wants_online = false; + } else if (m_accountToUse->accountState() != AccountState::Online) { + continue; // Something went wrong, try again + } + } } /* fallthrough */ case AccountState::Online: {