1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-22 12:47:44 +00:00

Enable typing in the password first, then remembering the password later

This commit is contained in:
Joshua Goins 2023-12-20 19:47:57 -05:00
parent 4da74915c9
commit 13a5fda828
5 changed files with 34 additions and 8 deletions

View file

@ -29,6 +29,7 @@ class Account : public QObject
Q_PROPERTY(bool useOTP READ useOTP WRITE setUseOTP NOTIFY useOTPChanged)
Q_PROPERTY(GameLicense license READ license WRITE setLicense NOTIFY licenseChanged)
Q_PROPERTY(bool isFreeTrial READ isFreeTrial WRITE setIsFreeTrial NOTIFY isFreeTrialChanged)
Q_PROPERTY(bool needsPassword READ needsPassword NOTIFY needsPasswordChanged)
public:
explicit Account(LauncherCore &launcher, const QString &key, QObject *parent = nullptr);
@ -82,6 +83,8 @@ public:
/// Updates FFXIV.cfg with some recommended options like turning the opening cutscene movie off
void updateConfig();
[[nodiscard]] bool needsPassword() const;
Q_SIGNALS:
void nameChanged();
void languageChanged();
@ -94,9 +97,11 @@ Q_SIGNALS:
void useOTPChanged();
void licenseChanged();
void isFreeTrialChanged();
bool needsPasswordChanged();
private:
void fetchAvatar();
QCoro::Task<> fetchPassword();
/*
* Sets a value in the keychain. This function is asynchronous.
@ -112,4 +117,5 @@ private:
QString m_key;
QString m_avatarUrl;
LauncherCore &m_launcher;
bool m_needsPassword = false;
};

View file

@ -23,6 +23,7 @@ Account::Account(LauncherCore &launcher, const QString &key, QObject *parent)
, m_launcher(launcher)
{
fetchAvatar();
fetchPassword();
}
QString Account::uuid() const
@ -184,6 +185,11 @@ QString Account::getPassword()
void Account::setPassword(const QString &password)
{
setKeychainValue(QStringLiteral("password"), password);
if (m_needsPassword) {
m_needsPassword = false;
Q_EMIT needsPasswordChanged();
}
}
QString Account::getOTP()
@ -327,4 +333,18 @@ void Account::updateConfig()
file.close();
}
bool Account::needsPassword() const
{
return m_needsPassword;
}
QCoro::Task<> Account::fetchPassword()
{
const QString password = co_await getKeychainValue(QStringLiteral("password"));
m_needsPassword = password.isEmpty();
Q_EMIT needsPasswordChanged();
co_return;
}
#include "moc_account.cpp"

View file

@ -210,7 +210,7 @@ bool LauncherCore::isSteam() const
bool LauncherCore::isSteamDeck() const
{
if (m_steamApi != nullptr) {
return m_steamApi->isDeck() || qEnvironmentVariable("XDG_CURRENT_DESKTOP") == QStringLiteral("gamescope");
return m_steamApi->isDeck() || qEnvironmentVariable("SteamDeck") == QStringLiteral("1");
} else {
return false;
}

View file

@ -94,7 +94,7 @@ int main(int argc, char *argv[])
return 0;
}
if (qEnvironmentVariable("XDG_CURRENT_DESKTOP") == QStringLiteral("gamescope")) {
if (qEnvironmentVariable("SteamDeck") == QStringLiteral("1")) {
isSteamDeck = true;
}
}

View file

@ -25,7 +25,7 @@ QQC2.Control {
return i18n("Username is required.");
}
if (!LauncherCore.currentProfile.account.rememberPassword && passwordField.text.length === 0) {
if (LauncherCore.currentProfile.account.needsPassword && passwordField.text.length === 0) {
return i18n("Password is required.");
}
@ -49,7 +49,7 @@ QQC2.Control {
return false;
}
if (!LauncherCore.currentProfile.account.rememberPassword && passwordField.text.length === 0) {
if (LauncherCore.currentProfile.account.needsPassword && passwordField.text.length === 0) {
return false;
}
@ -66,7 +66,7 @@ QQC2.Control {
function updateFields() {
usernameField.text = LauncherCore.currentProfile.account.name;
passwordField.text = LauncherCore.currentProfile.account.rememberPassword ? LauncherCore.currentProfile.account.getPassword() : "";
passwordField.text = !LauncherCore.currentProfile.account.needsPassword && LauncherCore.currentProfile.account.rememberPassword ? LauncherCore.currentProfile.account.getPassword() : "";
otpField.text = "";
}
@ -84,7 +84,7 @@ QQC2.Control {
function onAccountChanged() {
page.updateFields();
if (!LauncherCore.currentProfile.account.rememberPassword) {
if (LauncherCore.currentProfile.account.needsPassword) {
passwordField.forceActiveFocus();
return;
}
@ -206,7 +206,7 @@ QQC2.Control {
id: passwordField
label: LauncherCore.currentProfile.account.isSapphire ? i18n("Password") : i18n("Square Enix Password")
echoMode: TextInput.Password
enabled: !LauncherCore.currentProfile.account.rememberPassword
enabled: LauncherCore.currentProfile.account.needsPassword
focus: true
onAccepted: {
if (otpField.visible) {
@ -215,7 +215,7 @@ QQC2.Control {
loginButton.clicked();
}
}
text: LauncherCore.currentProfile.account.rememberPassword ? LauncherCore.currentProfile.account.getPassword() : ""
text: (!LauncherCore.currentProfile.account.needsPassword && LauncherCore.currentProfile.account.rememberPassword) ? LauncherCore.currentProfile.account.getPassword() : ""
}
FormCard.FormDelegateSeparator {