From 13a5fda82831cf27ce4e88ed77e7f1ecc5b02565 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 20 Dec 2023 19:47:57 -0500 Subject: [PATCH] Enable typing in the password first, then remembering the password later --- launcher/include/account.h | 6 ++++++ launcher/src/account.cpp | 20 ++++++++++++++++++++ launcher/src/launchercore.cpp | 2 +- launcher/src/main.cpp | 2 +- launcher/ui/Pages/LoginPage.qml | 12 ++++++------ 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/launcher/include/account.h b/launcher/include/account.h index 1fd0ae8..192b22a 100644 --- a/launcher/include/account.h +++ b/launcher/include/account.h @@ -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; }; \ No newline at end of file diff --git a/launcher/src/account.cpp b/launcher/src/account.cpp index 41557f0..6aad546 100644 --- a/launcher/src/account.cpp +++ b/launcher/src/account.cpp @@ -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" \ No newline at end of file diff --git a/launcher/src/launchercore.cpp b/launcher/src/launchercore.cpp index 71df439..a541dd0 100755 --- a/launcher/src/launchercore.cpp +++ b/launcher/src/launchercore.cpp @@ -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; } diff --git a/launcher/src/main.cpp b/launcher/src/main.cpp index 0aa1152..8e208f3 100755 --- a/launcher/src/main.cpp +++ b/launcher/src/main.cpp @@ -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; } } diff --git a/launcher/ui/Pages/LoginPage.qml b/launcher/ui/Pages/LoginPage.qml index 431c2e4..1d71d5f 100644 --- a/launcher/ui/Pages/LoginPage.qml +++ b/launcher/ui/Pages/LoginPage.qml @@ -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 {