1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-24 05:17:46 +00:00

Remove LauncherCore dependency injection in Account/AccountManager

This is no longer needed, and we will need this to test this model
standalone.
This commit is contained in:
Joshua Goins 2024-08-22 18:53:46 -04:00
parent a22ddd13b7
commit 51d9551667
5 changed files with 8 additions and 21 deletions

View file

@ -3,15 +3,12 @@
#pragma once #pragma once
#include <QDir>
#include <QObject> #include <QObject>
#include <QtQml> #include <QtQml>
#include <qcorotask.h> #include <qcorotask.h>
#include "accountconfig.h" #include "accountconfig.h"
class LauncherCore;
class Account : public QObject class Account : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -32,7 +29,7 @@ class Account : public QObject
Q_PROPERTY(bool needsPassword READ needsPassword NOTIFY needsPasswordChanged) Q_PROPERTY(bool needsPassword READ needsPassword NOTIFY needsPasswordChanged)
public: public:
explicit Account(LauncherCore &launcher, const QString &key, QObject *parent = nullptr); explicit Account(const QString &key, QObject *parent = nullptr);
enum class GameLicense { WindowsStandalone, WindowsSteam, macOS }; enum class GameLicense { WindowsStandalone, WindowsSteam, macOS };
Q_ENUM(GameLicense) Q_ENUM(GameLicense)
@ -115,6 +112,5 @@ private:
AccountConfig m_config; AccountConfig m_config;
QString m_key; QString m_key;
QString m_avatarUrl; QString m_avatarUrl;
LauncherCore &m_launcher;
bool m_needsPassword = false; bool m_needsPassword = false;
}; };

View file

@ -3,8 +3,6 @@
#pragma once #pragma once
#include <QAbstractListModel>
#include "account.h" #include "account.h"
class AccountManager : public QAbstractListModel class AccountManager : public QAbstractListModel
@ -16,7 +14,7 @@ class AccountManager : public QAbstractListModel
Q_PROPERTY(int numAccounts READ numAccounts NOTIFY accountsChanged) Q_PROPERTY(int numAccounts READ numAccounts NOTIFY accountsChanged)
public: public:
explicit AccountManager(LauncherCore &launcher, QObject *parent = nullptr); explicit AccountManager(QObject *parent = nullptr);
void load(); void load();
@ -50,6 +48,4 @@ private:
void insertAccount(Account *account); void insertAccount(Account *account);
QList<Account *> m_accounts; QList<Account *> m_accounts;
LauncherCore &m_launcher;
}; };

View file

@ -3,23 +3,19 @@
#include "account.h" #include "account.h"
#include <QNetworkReply>
#include <QNetworkRequest>
#include <cotp.h> #include <cotp.h>
#include <qcorocore.h> #include <qcorocore.h>
#include <qt6keychain/keychain.h> #include <qt6keychain/keychain.h>
#include "astra_log.h" #include "astra_log.h"
#include "launchercore.h"
#include "utility.h" #include "utility.h"
using namespace Qt::StringLiterals; using namespace Qt::StringLiterals;
Account::Account(LauncherCore &launcher, const QString &key, QObject *parent) Account::Account(const QString &key, QObject *parent)
: QObject(parent) : QObject(parent)
, m_config(key) , m_config(key)
, m_key(key) , m_key(key)
, m_launcher(launcher)
{ {
fetchPassword(); fetchPassword();
} }

View file

@ -8,9 +8,8 @@
using namespace Qt::StringLiterals; using namespace Qt::StringLiterals;
AccountManager::AccountManager(LauncherCore &launcher, QObject *parent) AccountManager::AccountManager(QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
, m_launcher(launcher)
{ {
} }
@ -22,7 +21,7 @@ void AccountManager::load()
const QString uuid = QString(id).remove("account-"_L1); const QString uuid = QString(id).remove("account-"_L1);
qInfo(ASTRA_LOG) << "Loading account" << uuid; qInfo(ASTRA_LOG) << "Loading account" << uuid;
const auto account = new Account(m_launcher, uuid, this); const auto account = new Account(uuid, this);
m_accounts.append(account); m_accounts.append(account);
Q_EMIT accountsChanged(); Q_EMIT accountsChanged();
} }
@ -56,7 +55,7 @@ QHash<int, QByteArray> AccountManager::roleNames() const
Account *AccountManager::createSquareEnixAccount(const QString &username, const int licenseType, const bool isFreeTrial) Account *AccountManager::createSquareEnixAccount(const QString &username, const int licenseType, const bool isFreeTrial)
{ {
const auto account = new Account(m_launcher, QUuid::createUuid().toString(), this); const auto account = new Account(QUuid::createUuid().toString(), this);
account->setIsSapphire(false); account->setIsSapphire(false);
account->setLicense(static_cast<Account::GameLicense>(licenseType)); account->setLicense(static_cast<Account::GameLicense>(licenseType));
account->setIsFreeTrial(isFreeTrial); account->setIsFreeTrial(isFreeTrial);
@ -69,7 +68,7 @@ Account *AccountManager::createSquareEnixAccount(const QString &username, const
Account *AccountManager::createSapphireAccount(const QString &lobbyUrl, const QString &username) Account *AccountManager::createSapphireAccount(const QString &lobbyUrl, const QString &username)
{ {
const auto account = new Account(m_launcher, QUuid::createUuid().toString(), this); const auto account = new Account(QUuid::createUuid().toString(), this);
account->setIsSapphire(true); account->setIsSapphire(true);
account->setName(username); account->setName(username);
account->setLobbyUrl(lobbyUrl); account->setLobbyUrl(lobbyUrl);

View file

@ -37,7 +37,7 @@ LauncherCore::LauncherCore()
m_sapphireLogin = new SapphireLogin(*this, this); m_sapphireLogin = new SapphireLogin(*this, this);
m_squareEnixLogin = new SquareEnixLogin(*this, this); m_squareEnixLogin = new SquareEnixLogin(*this, this);
m_profileManager = new ProfileManager(this); m_profileManager = new ProfileManager(this);
m_accountManager = new AccountManager(*this, this); m_accountManager = new AccountManager(this);
m_runner = new GameRunner(*this, this); m_runner = new GameRunner(*this, this);
connect(m_accountManager, &AccountManager::accountAdded, this, &LauncherCore::fetchAvatar); connect(m_accountManager, &AccountManager::accountAdded, this, &LauncherCore::fetchAvatar);