NOISSUE fix up some corner cases around migrating accounts
This commit is contained in:
parent
3a940ffb52
commit
825ef52dd5
@ -89,9 +89,18 @@ QStringList AccountList::profileNames() const {
|
|||||||
|
|
||||||
void AccountList::addAccount(const MinecraftAccountPtr account)
|
void AccountList::addAccount(const MinecraftAccountPtr account)
|
||||||
{
|
{
|
||||||
|
// NOTE: Do not allow adding something that's already there
|
||||||
|
if(m_accounts.contains(account)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// hook up notifications for changes in the account
|
||||||
|
connect(account.get(), &MinecraftAccount::changed, this, &AccountList::accountChanged);
|
||||||
|
connect(account.get(), &MinecraftAccount::activityChanged, this, &AccountList::accountActivityChanged);
|
||||||
|
|
||||||
|
// override/replace existing account with the same profileId
|
||||||
auto profileId = account->profileId();
|
auto profileId = account->profileId();
|
||||||
if(profileId.size()) {
|
if(profileId.size()) {
|
||||||
// override/replace existing account with the same profileId
|
|
||||||
auto existingAccount = findAccountByProfileId(profileId);
|
auto existingAccount = findAccountByProfileId(profileId);
|
||||||
if(existingAccount != -1) {
|
if(existingAccount != -1) {
|
||||||
MinecraftAccountPtr existingAccountPtr = m_accounts[existingAccount];
|
MinecraftAccountPtr existingAccountPtr = m_accounts[existingAccount];
|
||||||
@ -99,6 +108,8 @@ void AccountList::addAccount(const MinecraftAccountPtr account)
|
|||||||
if(m_defaultAccount == existingAccountPtr) {
|
if(m_defaultAccount == existingAccountPtr) {
|
||||||
m_defaultAccount = account;
|
m_defaultAccount = account;
|
||||||
}
|
}
|
||||||
|
// disconnect notifications for changes in the account being replaced
|
||||||
|
existingAccountPtr->disconnect(this);
|
||||||
emit dataChanged(index(existingAccount), index(existingAccount, columnCount(QModelIndex()) - 1));
|
emit dataChanged(index(existingAccount), index(existingAccount, columnCount(QModelIndex()) - 1));
|
||||||
onListChanged();
|
onListChanged();
|
||||||
return;
|
return;
|
||||||
@ -108,8 +119,6 @@ void AccountList::addAccount(const MinecraftAccountPtr account)
|
|||||||
// if we don't have this profileId yet, add the account to the end
|
// if we don't have this profileId yet, add the account to the end
|
||||||
int row = m_accounts.count();
|
int row = m_accounts.count();
|
||||||
beginInsertRows(QModelIndex(), row, row);
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
connect(account.get(), &MinecraftAccount::changed, this, &AccountList::accountChanged);
|
|
||||||
connect(account.get(), &MinecraftAccount::activityChanged, this, &AccountList::accountActivityChanged);
|
|
||||||
m_accounts.append(account);
|
m_accounts.append(account);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
onListChanged();
|
onListChanged();
|
||||||
@ -126,6 +135,8 @@ void AccountList::removeAccount(QModelIndex index)
|
|||||||
m_defaultAccount = nullptr;
|
m_defaultAccount = nullptr;
|
||||||
onDefaultAccountChanged();
|
onDefaultAccountChanged();
|
||||||
}
|
}
|
||||||
|
account->disconnect(this);
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
m_accounts.removeAt(index.row());
|
m_accounts.removeAt(index.row());
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
@ -204,6 +215,12 @@ void AccountList::accountActivityChanged(bool active)
|
|||||||
}
|
}
|
||||||
if(found) {
|
if(found) {
|
||||||
emit listActivityChanged();
|
emit listActivityChanged();
|
||||||
|
if(active) {
|
||||||
|
beginActivity();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
endActivity();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,7 +680,6 @@ void AccountList::queueRefresh(QString accountId) {
|
|||||||
|
|
||||||
|
|
||||||
void AccountList::tryNext() {
|
void AccountList::tryNext() {
|
||||||
beginActivity();
|
|
||||||
while (m_refreshQueue.length()) {
|
while (m_refreshQueue.length()) {
|
||||||
auto accountId = m_refreshQueue.front();
|
auto accountId = m_refreshQueue.front();
|
||||||
m_refreshQueue.pop_front();
|
m_refreshQueue.pop_front();
|
||||||
@ -682,7 +698,6 @@ void AccountList::tryNext() {
|
|||||||
}
|
}
|
||||||
qDebug() << "RefreshSchedule: Account with with internal ID " << accountId << " not found.";
|
qDebug() << "RefreshSchedule: Account with with internal ID " << accountId << " not found.";
|
||||||
}
|
}
|
||||||
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(1000 * 3600);
|
m_refreshTimer->start(1000 * 3600);
|
||||||
}
|
}
|
||||||
@ -690,14 +705,12 @@ void AccountList::tryNext() {
|
|||||||
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();
|
|
||||||
m_nextTimer->start(1000 * 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();
|
|
||||||
m_nextTimer->start(1000 * 20);
|
m_nextTimer->start(1000 * 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user