| 127 | } |
| 128 | |
| 129 | LaunchDecision LaunchController::decideLaunchMode() |
| 130 | { |
| 131 | if (!m_accountToUse || m_wantedLaunchMode == LaunchMode::Demo) { |
| 132 | m_actualLaunchMode = LaunchMode::Demo; |
| 133 | return LaunchDecision::Continue; |
| 134 | } |
| 135 | |
| 136 | if (m_wantedLaunchMode == LaunchMode::Normal) { |
| 137 | if (m_accountToUse->shouldRefresh() || m_accountToUse->accountState() == AccountState::Offline) { |
| 138 | // Force account refresh on the account used to launch the instance updating the AccountState |
| 139 | // only on first try and if it is not meant to be offline |
| 140 | m_accountToUse->refresh(); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | const auto* accounts = APPLICATION->accounts(); |
| 145 | MinecraftAccountPtr accountToCheck = nullptr; |
| 146 | |
| 147 | if (m_accountToUse->accountType() != AccountType::Offline) { |
| 148 | accountToCheck = m_accountToUse->ownsMinecraft() ? m_accountToUse : nullptr; |
| 149 | } else if (const auto defaultAccount = accounts->defaultAccount(); defaultAccount && defaultAccount->ownsMinecraft()) { |
| 150 | accountToCheck = defaultAccount; |
| 151 | } else { |
| 152 | for (int i = 0; i < accounts->count(); i++) { |
| 153 | if (const auto account = accounts->at(i); account->ownsMinecraft()) { |
| 154 | accountToCheck = account; |
| 155 | break; |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | if (!accountToCheck) { |
| 161 | m_actualLaunchMode = LaunchMode::Demo; |
| 162 | return LaunchDecision::Continue; |
| 163 | } |
| 164 | |
| 165 | auto state = accountToCheck->accountState(); |
| 166 | if (state == AccountState::Unchecked || state == AccountState::Errored) { |
| 167 | accountToCheck->refresh(); |
| 168 | state = AccountState::Working; |
| 169 | } |
| 170 | |
| 171 | if (state == AccountState::Working) { |
| 172 | // refresh is in progress, we need to wait for it to finish to proceed. |
| 173 | ProgressDialog progDialog(m_parentWidget); |
| 174 | progDialog.setSkipButton(true, tr("Abort")); |
| 175 | |
| 176 | // TODO: this relies on tasks' synchronous signal dispatching nature |
| 177 | // TODO: meaning currentTask can't complete and become null while this code is running |
| 178 | // TODO: this code will produce a race condition when tasks become fully async |
| 179 | auto task = accountToCheck->currentTask(); |
| 180 | progDialog.execWithTask(task.get()); |
| 181 | |
| 182 | if (task->getState() == State::AbortedByUser) { |
| 183 | return LaunchDecision::Abort; |
| 184 | } |
| 185 | |
| 186 | state = accountToCheck->accountState(); |
nothing calls this directly
no test coverage detected