1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-20 19:57:45 +00:00

Prevent auto login loop, and stop from logging in twice

This commit is contained in:
Joshua Goins 2023-09-17 19:30:22 -04:00
parent 201f4df179
commit 7e2992ead2
7 changed files with 46 additions and 12 deletions

View file

@ -106,7 +106,7 @@ public:
/* /*
* Launches the game using the provided authentication. * Launches the game using the provided authentication.
*/ */
void launchGame(const Profile &settings, const LoginAuth &auth); void launchGame(Profile &settings, const LoginAuth &auth);
/* /*
* This just wraps it in wine if needed. * This just wraps it in wine if needed.
@ -190,17 +190,17 @@ private:
/* /*
* Begins the game executable, but calls to Dalamud if needed. * Begins the game executable, but calls to Dalamud if needed.
*/ */
void beginGameExecutable(const Profile &settings, const LoginAuth &auth); void beginGameExecutable(Profile &settings, const LoginAuth &auth);
/* /*
* Starts a vanilla game session with no Dalamud injection. * Starts a vanilla game session with no Dalamud injection.
*/ */
void beginVanillaGame(const QString &gameExecutablePath, const Profile &profile, const LoginAuth &auth); void beginVanillaGame(const QString &gameExecutablePath, Profile &profile, const LoginAuth &auth);
/* /*
* Starts a game session with Dalamud injected. * Starts a game session with Dalamud injected.
*/ */
void beginDalamudGame(const QString &gameExecutablePath, const Profile &profile, const LoginAuth &auth); void beginDalamudGame(const QString &gameExecutablePath, Profile &profile, const LoginAuth &auth);
/* /*
* Returns the game arguments needed to properly launch the game. This encrypts it too if needed, and it's already * Returns the game arguments needed to properly launch the game. This encrypts it too if needed, and it's already

View file

@ -41,6 +41,7 @@ class Profile : public QObject
Q_PROPERTY(QString expansionVersionText READ expansionVersionText NOTIFY gameInstallChanged) Q_PROPERTY(QString expansionVersionText READ expansionVersionText NOTIFY gameInstallChanged)
Q_PROPERTY(QString dalamudVersionText READ dalamudVersionText NOTIFY gameInstallChanged) Q_PROPERTY(QString dalamudVersionText READ dalamudVersionText NOTIFY gameInstallChanged)
Q_PROPERTY(QString wineVersionText READ wineVersionText NOTIFY wineChanged) Q_PROPERTY(QString wineVersionText READ wineVersionText NOTIFY wineChanged)
Q_PROPERTY(bool loggedIn READ loggedIn NOTIFY loggedInChanged)
public: public:
explicit Profile(LauncherCore &launcher, const QString &key, QObject *parent = nullptr); explicit Profile(LauncherCore &launcher, const QString &key, QObject *parent = nullptr);
@ -148,6 +149,9 @@ public:
BootData *bootData(); BootData *bootData();
GameData *gameData(); GameData *gameData();
bool loggedIn() const;
void setLoggedIn(bool value);
Q_SIGNALS: Q_SIGNALS:
void gameInstallChanged(); void gameInstallChanged();
void nameChanged(); void nameChanged();
@ -171,6 +175,7 @@ Q_SIGNALS:
void encryptedArgumentsChanged(); void encryptedArgumentsChanged();
void accountChanged(); void accountChanged();
void wineChanged(); void wineChanged();
void loggedInChanged();
private: private:
QString m_uuid; QString m_uuid;
@ -190,5 +195,7 @@ private:
int m_dalamudAssetVersion = -1; int m_dalamudAssetVersion = -1;
QString m_runtimeVersion; QString m_runtimeVersion;
bool m_loggedIn = false;
LauncherCore &m_launcher; LauncherCore &m_launcher;
}; };

View file

@ -56,7 +56,7 @@ void LauncherCore::buildRequest(const Profile &settings, QNetworkRequest &reques
request.setRawHeader(QByteArrayLiteral("Accept-Language"), QByteArrayLiteral("en-us")); request.setRawHeader(QByteArrayLiteral("Accept-Language"), QByteArrayLiteral("en-us"));
} }
void LauncherCore::launchGame(const Profile &profile, const LoginAuth &auth) void LauncherCore::launchGame(Profile &profile, const LoginAuth &auth)
{ {
m_steamApi->setLauncherMode(false); m_steamApi->setLauncherMode(false);
@ -87,7 +87,7 @@ QCoro::Task<> LauncherCore::beginLogin(LoginInformation &info)
assetUpdater->deleteLater(); assetUpdater->deleteLater();
} }
void LauncherCore::beginGameExecutable(const Profile &profile, const LoginAuth &auth) void LauncherCore::beginGameExecutable(Profile &profile, const LoginAuth &auth)
{ {
Q_EMIT stageChanged(i18n("Launching game...")); Q_EMIT stageChanged(i18n("Launching game..."));
@ -104,14 +104,17 @@ void LauncherCore::beginGameExecutable(const Profile &profile, const LoginAuth &
beginVanillaGame(gameExectuable, profile, auth); beginVanillaGame(gameExectuable, profile, auth);
} }
successfulLaunch(); Q_EMIT successfulLaunch();
} }
void LauncherCore::beginVanillaGame(const QString &gameExecutablePath, const Profile &profile, const LoginAuth &auth) void LauncherCore::beginVanillaGame(const QString &gameExecutablePath, Profile &profile, const LoginAuth &auth)
{ {
profile.setLoggedIn(true);
auto gameProcess = new QProcess(this); auto gameProcess = new QProcess(this);
gameProcess->setProcessEnvironment(QProcessEnvironment::systemEnvironment()); gameProcess->setProcessEnvironment(QProcessEnvironment::systemEnvironment());
connect(gameProcess, &QProcess::finished, this, [this](int exitCode) { connect(gameProcess, &QProcess::finished, this, [this, &profile](int exitCode) {
profile.setLoggedIn(false);
Q_UNUSED(exitCode) Q_UNUSED(exitCode)
Q_EMIT gameClosed(); Q_EMIT gameClosed();
}); });
@ -121,8 +124,10 @@ void LauncherCore::beginVanillaGame(const QString &gameExecutablePath, const Pro
launchExecutable(profile, gameProcess, {gameExecutablePath, args}, true, true); launchExecutable(profile, gameProcess, {gameExecutablePath, args}, true, true);
} }
void LauncherCore::beginDalamudGame(const QString &gameExecutablePath, const Profile &profile, const LoginAuth &auth) void LauncherCore::beginDalamudGame(const QString &gameExecutablePath, Profile &profile, const LoginAuth &auth)
{ {
profile.setLoggedIn(true);
const QDir dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); const QDir dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
const QDir configDir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); const QDir configDir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
const QDir stateDir = Utility::stateDirectory(); const QDir stateDir = Utility::stateDirectory();
@ -151,7 +156,8 @@ void LauncherCore::beginDalamudGame(const QString &gameExecutablePath, const Pro
const QString dalamudInjector = dalamudInstallDir.absoluteFilePath(QStringLiteral("Dalamud.Injector.exe")); const QString dalamudInjector = dalamudInstallDir.absoluteFilePath(QStringLiteral("Dalamud.Injector.exe"));
auto dalamudProcess = new QProcess(this); auto dalamudProcess = new QProcess(this);
connect(dalamudProcess, &QProcess::finished, this, [this](int exitCode) { connect(dalamudProcess, &QProcess::finished, this, [this, &profile](int exitCode) {
profile.setLoggedIn(false);
Q_UNUSED(exitCode) Q_UNUSED(exitCode)
Q_EMIT gameClosed(); Q_EMIT gameClosed();
}); });

View file

@ -574,3 +574,16 @@ GameData *Profile::gameData()
{ {
return m_gameData; return m_gameData;
} }
bool Profile::loggedIn() const
{
return m_loggedIn;
}
void Profile::setLoggedIn(const bool value)
{
if (m_loggedIn != value) {
m_loggedIn = value;
Q_EMIT loggedInChanged();
}
}

View file

@ -22,6 +22,8 @@ Kirigami.ApplicationWindow {
visible: true visible: true
title: LauncherCore.isSteam ? "Astra (Steam)" : "Astra" title: LauncherCore.isSteam ? "Astra (Steam)" : "Astra"
property bool checkedAutoLogin: false
pageStack.initialPage: Kirigami.Page { pageStack.initialPage: Kirigami.Page {
Kirigami.LoadingPlaceholder { Kirigami.LoadingPlaceholder {
anchors.centerIn: parent anchors.centerIn: parent
@ -46,8 +48,9 @@ Kirigami.ApplicationWindow {
profile: LauncherCore.currentProfile profile: LauncherCore.currentProfile
}) })
} else { } else {
if (LauncherCore.autoLoginProfile) { if (LauncherCore.autoLoginProfile && !checkedAutoLogin) {
pageStack.layers.replace(Qt.createComponent("zone.xiv.astra", "AutoLoginPage")) pageStack.layers.replace(Qt.createComponent("zone.xiv.astra", "AutoLoginPage"))
checkedAutoLogin = true;
} else { } else {
pageStack.layers.replace(Qt.createComponent("zone.xiv.astra", "MainPage")) pageStack.layers.replace(Qt.createComponent("zone.xiv.astra", "MainPage"))
} }

View file

@ -37,6 +37,7 @@ Kirigami.Page {
interval: 5000 interval: 5000
running: true running: true
onTriggered: { onTriggered: {
autoLoginTimer.stop();
LauncherCore.autoLogin(LauncherCore.autoLoginProfile); LauncherCore.autoLogin(LauncherCore.autoLoginProfile);
pageStack.layers.push(Qt.createComponent("zone.xiv.astra", "StatusPage")); pageStack.layers.push(Qt.createComponent("zone.xiv.astra", "StatusPage"));
} }

View file

@ -31,6 +31,10 @@ QQC2.Control {
return false return false
} }
if (LauncherCore.currentProfile.loggedIn) {
return false;
}
return true; return true;
} }