diff --git a/launcher/minecraft/auth/AccountList.cpp b/launcher/minecraft/auth/AccountList.cpp index f7866f37..c96e8766 100644 --- a/launcher/minecraft/auth/AccountList.cpp +++ b/launcher/minecraft/auth/AccountList.cpp @@ -635,21 +635,33 @@ void AccountList::fillQueue() { if(account->shouldRefresh()) { auto idToRefresh = account->internalId(); - m_refreshQueue.push_back(idToRefresh); - qDebug() << "AccountList: Queued account with internal ID " << idToRefresh << " to refresh"; + queueRefresh(idToRefresh); } } - m_refreshQueue.removeDuplicates(); tryNext(); } void AccountList::requestRefresh(QString accountId) { - m_refreshQueue.push_back(accountId); + auto index = m_refreshQueue.indexOf(accountId); + if(index != -1) { + m_refreshQueue.removeAt(index); + } + m_refreshQueue.push_front(accountId); + qDebug() << "AccountList: Pushed account with internal ID " << accountId << " to the front of the queue"; if(!isActive()) { tryNext(); } } +void AccountList::queueRefresh(QString accountId) { + if(m_refreshQueue.indexOf(accountId) != -1) { + return; + } + m_refreshQueue.push_back(accountId); + qDebug() << "AccountList: Queued account with internal ID " << accountId << " to refresh"; +} + + void AccountList::tryNext() { beginActivity(); while (m_refreshQueue.length()) { @@ -672,21 +684,21 @@ void AccountList::tryNext() { } endActivity(); // if we get here, no account needed refreshing. Schedule refresh in an hour. - m_refreshTimer->start(std::chrono::hours(1)); + m_refreshTimer->start(1000 * 3600); } void AccountList::authSucceeded() { qDebug() << "RefreshSchedule: Background account refresh succeeded"; m_currentTask.reset(); endActivity(); - m_nextTimer->start(std::chrono::seconds(20)); + m_nextTimer->start(1000 * 20); } void AccountList::authFailed(QString reason) { qDebug() << "RefreshSchedule: Background account refresh failed: " << reason; m_currentTask.reset(); endActivity(); - m_nextTimer->start(std::chrono::seconds(20)); + m_nextTimer->start(1000 * 20); } bool AccountList::isActive() const { diff --git a/launcher/minecraft/auth/AccountList.h b/launcher/minecraft/auth/AccountList.h index 75686c21..fa1e7431 100644 --- a/launcher/minecraft/auth/AccountList.h +++ b/launcher/minecraft/auth/AccountList.h @@ -67,7 +67,10 @@ public: MinecraftAccountPtr getAccountByProfileName(const QString &profileName) const; QStringList profileNames() const; + // requesting a refresh pushes it to the front of the queue void requestRefresh(QString accountId); + // queuing a refresh will let it go to the back of the queue (unless it's somewhere inside the queue already) + void queueRefresh(QString accountId); /*! * Sets the path to load/save the list file from/to. diff --git a/launcher/minecraft/auth/MinecraftAccount.cpp b/launcher/minecraft/auth/MinecraftAccount.cpp index 7ce87a3d..ed9e945e 100644 --- a/launcher/minecraft/auth/MinecraftAccount.cpp +++ b/launcher/minecraft/auth/MinecraftAccount.cpp @@ -211,7 +211,7 @@ bool MinecraftAccount::shouldRefresh() const { if(!expiresTimestamp.isValid()) { expiresTimestamp = issuedTimestamp.addSecs(24 * 3600); } - if (now.secsTo(expiresTimestamp) < 12 * 3600) { + if (now.secsTo(expiresTimestamp) < (12 * 3600)) { return true; } return false;