NOISSUE fix builds, make account refresh queue user friendly

This commit is contained in:
Petr Mrázek 2021-12-04 02:10:14 +01:00
parent db6431d9e0
commit d37003b1de
3 changed files with 23 additions and 8 deletions

View File

@ -635,21 +635,33 @@ void AccountList::fillQueue() {
if(account->shouldRefresh()) { if(account->shouldRefresh()) {
auto idToRefresh = account->internalId(); auto idToRefresh = account->internalId();
m_refreshQueue.push_back(idToRefresh); queueRefresh(idToRefresh);
qDebug() << "AccountList: Queued account with internal ID " << idToRefresh << " to refresh";
} }
} }
m_refreshQueue.removeDuplicates();
tryNext(); tryNext();
} }
void AccountList::requestRefresh(QString accountId) { 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()) { if(!isActive()) {
tryNext(); 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() { void AccountList::tryNext() {
beginActivity(); beginActivity();
while (m_refreshQueue.length()) { while (m_refreshQueue.length()) {
@ -672,21 +684,21 @@ void AccountList::tryNext() {
} }
endActivity(); endActivity();
// if we get here, no account needed refreshing. Schedule refresh in an hour. // 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() { void AccountList::authSucceeded() {
qDebug() << "RefreshSchedule: Background account refresh succeeded"; qDebug() << "RefreshSchedule: Background account refresh succeeded";
m_currentTask.reset(); m_currentTask.reset();
endActivity(); endActivity();
m_nextTimer->start(std::chrono::seconds(20)); m_nextTimer->start(1000 * 20);
} }
void AccountList::authFailed(QString reason) { void AccountList::authFailed(QString reason) {
qDebug() << "RefreshSchedule: Background account refresh failed: " << reason; qDebug() << "RefreshSchedule: Background account refresh failed: " << reason;
m_currentTask.reset(); m_currentTask.reset();
endActivity(); endActivity();
m_nextTimer->start(std::chrono::seconds(20)); m_nextTimer->start(1000 * 20);
} }
bool AccountList::isActive() const { bool AccountList::isActive() const {

View File

@ -67,7 +67,10 @@ public:
MinecraftAccountPtr getAccountByProfileName(const QString &profileName) const; MinecraftAccountPtr getAccountByProfileName(const QString &profileName) const;
QStringList profileNames() const; QStringList profileNames() const;
// requesting a refresh pushes it to the front of the queue
void requestRefresh(QString accountId); 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. * Sets the path to load/save the list file from/to.

View File

@ -211,7 +211,7 @@ bool MinecraftAccount::shouldRefresh() const {
if(!expiresTimestamp.isValid()) { if(!expiresTimestamp.isValid()) {
expiresTimestamp = issuedTimestamp.addSecs(24 * 3600); expiresTimestamp = issuedTimestamp.addSecs(24 * 3600);
} }
if (now.secsTo(expiresTimestamp) < 12 * 3600) { if (now.secsTo(expiresTimestamp) < (12 * 3600)) {
return true; return true;
} }
return false; return false;