1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-25 05:47:45 +00:00

Disable the account switcher when there's only one account

This commit is contained in:
Joshua Goins 2024-04-01 15:15:30 -04:00
parent 4abe56ea82
commit 5078da4e84
3 changed files with 9 additions and 0 deletions

View file

@ -14,6 +14,8 @@ class AccountManager : public QAbstractListModel
QML_ELEMENT QML_ELEMENT
QML_UNCREATABLE("Use LauncherCore.accountManager") QML_UNCREATABLE("Use LauncherCore.accountManager")
Q_PROPERTY(int numAccounts READ numAccounts NOTIFY accountsChanged)
public: public:
explicit AccountManager(LauncherCore &launcher, QObject *parent = nullptr); explicit AccountManager(LauncherCore &launcher, QObject *parent = nullptr);
@ -40,6 +42,9 @@ public:
Q_INVOKABLE [[nodiscard]] bool hasAnyAccounts() const; Q_INVOKABLE [[nodiscard]] bool hasAnyAccounts() const;
Q_INVOKABLE [[nodiscard]] int numAccounts() const; Q_INVOKABLE [[nodiscard]] int numAccounts() const;
Q_SIGNALS:
void accountsChanged();
private: private:
void insertAccount(Account *account); void insertAccount(Account *account);

View file

@ -24,6 +24,7 @@ void AccountManager::load()
auto account = new Account(m_launcher, uuid, this); auto account = new Account(m_launcher, uuid, this);
m_accounts.append(account); m_accounts.append(account);
Q_EMIT accountsChanged();
} }
} }
} }
@ -105,6 +106,7 @@ void AccountManager::deleteAccount(Account *account)
beginRemoveRows(QModelIndex(), row, row); beginRemoveRows(QModelIndex(), row, row);
m_accounts.removeAll(account); m_accounts.removeAll(account);
endRemoveRows(); endRemoveRows();
Q_EMIT accountsChanged();
} }
void AccountManager::insertAccount(Account *account) void AccountManager::insertAccount(Account *account)
@ -112,6 +114,7 @@ void AccountManager::insertAccount(Account *account)
beginInsertRows(QModelIndex(), static_cast<int>(m_accounts.size()), static_cast<int>(m_accounts.size())); beginInsertRows(QModelIndex(), static_cast<int>(m_accounts.size()), static_cast<int>(m_accounts.size()));
m_accounts.append(account); m_accounts.append(account);
endInsertRows(); endInsertRows();
Q_EMIT accountsChanged();
} }
bool AccountManager::hasAnyAccounts() const bool AccountManager::hasAnyAccounts() const

View file

@ -165,6 +165,7 @@ QQC2.Control {
FormCard.FormButtonDelegate { FormCard.FormButtonDelegate {
id: currentAccountDelegate id: currentAccountDelegate
enabled: LauncherCore.accountManager.numAccounts > 1
text: LauncherCore.currentProfile.account.name text: LauncherCore.currentProfile.account.name
leading: Components.Avatar { leading: Components.Avatar {