From fba18c2719c8a3f6a47de62ee15ce03f16087783 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 8 Oct 2019 12:55:02 -0700 Subject: [PATCH] Fixup qt launcher style and add last login --- .../qml/HFBase/CreateAccountBase.qml | 5 ++-- .../qt/resources/qml/HFBase/LoginBase.qml | 1 + launchers/qt/src/LauncherState.cpp | 30 +++++++++++++++---- launchers/qt/src/LauncherState.h | 4 +++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/launchers/qt/resources/qml/HFBase/CreateAccountBase.qml b/launchers/qt/resources/qml/HFBase/CreateAccountBase.qml index cf03b282bf..dd23862303 100644 --- a/launchers/qt/resources/qml/HFBase/CreateAccountBase.qml +++ b/launchers/qt/resources/qml/HFBase/CreateAccountBase.qml @@ -9,7 +9,7 @@ Item { id: root anchors.centerIn: parent property string titleText: "Sign-in and pick a password" - property string usernamePlaceholder: "User name" + property string usernamePlaceholder: "Username" property string passwordPlaceholder: "Set a password" property int marginLeft: root.width * 0.15 @@ -30,8 +30,7 @@ Item { width: 481 lineHeight: 35 lineHeightMode: Text.FixedHeight - text: root.titleText + " " + LauncherState.applicationState - visible: LauncherState.lastSignupErrorMessage.length == 0 ? root.titleText : "Uh oh." + text: LauncherState.lastSignupErrorMessage.length == 0 ? root.titleText : "Uh oh." anchors { top: root.top topMargin: 29 diff --git a/launchers/qt/resources/qml/HFBase/LoginBase.qml b/launchers/qt/resources/qml/HFBase/LoginBase.qml index f30ce7bcd5..98d7500890 100644 --- a/launchers/qt/resources/qml/HFBase/LoginBase.qml +++ b/launchers/qt/resources/qml/HFBase/LoginBase.qml @@ -78,6 +78,7 @@ Item { enabled: root.enabled + text: LauncherState.lastUsedUsername placeholderText: "Username" seperatorColor: Qt.rgba(1, 1, 1, 0.3) diff --git a/launchers/qt/src/LauncherState.cpp b/launchers/qt/src/LauncherState.cpp index ddb5ab2dd8..71e15b577b 100644 --- a/launchers/qt/src/LauncherState.cpp +++ b/launchers/qt/src/LauncherState.cpp @@ -31,6 +31,7 @@ //#define BREAK_ON_ERROR const QString configHomeLocationKey { "homeLocation" }; +const QString configLastLoginKey { "lastLogin" }; const QString configLoggedInKey{ "loggedIn" }; const QString configLauncherPathKey{ "launcherPath" }; @@ -261,10 +262,16 @@ void LauncherState::getCurrentClientVersion() { _config.launcherPath = getLauncherFilePath(); _config.loggedIn = false; if (root.contains(configLoggedInKey)) { - _config.loggedIn = root["loggedIn"].toBool(); + _config.loggedIn = root[configLoggedInKey].toBool(); + } + if (root.contains(configLastLoginKey)) { + _config.lastLogin = root[configLastLoginKey].toString(); } if (root.contains(configHomeLocationKey)) { - _config.homeLocation = root["homeLocation"].toString(); + _config.homeLocation = root[configHomeLocationKey].toString(); + } + if (root.contains(configLauncherPathKey)) { + _config.launcherPath = root[configLauncherPathKey].toString(); } } else { qDebug() << "Failed to open config.json"; @@ -274,7 +281,12 @@ void LauncherState::getCurrentClientVersion() { if (_config.loggedIn) { downloadClient(); } else { - setApplicationState(ApplicationState::WaitingForSignup); + if (_config.lastLogin.isEmpty()) { + setApplicationState(ApplicationState::WaitingForSignup); + } else { + _lastUsedUsername = _config.lastLogin; + setApplicationState(ApplicationState::WaitingForLogin); + } } } @@ -312,7 +324,7 @@ void LauncherState::signup(QString email, QString username, QString password, QS emit lastSignupErrorChanged(); } - QObject::connect(signupRequest, &SignupRequest::finished, this, [this, signupRequest] { + QObject::connect(signupRequest, &SignupRequest::finished, this, [this, signupRequest, username] { signupRequest->deleteLater(); @@ -350,6 +362,9 @@ void LauncherState::signup(QString email, QString username, QString password, QS // After successfully signing up, attempt to login auto loginRequest = new LoginRequest(); + _lastUsedUsername = username; + _config.lastLogin = username; + connect(loginRequest, &LoginRequest::finished, this, [this, loginRequest]() { ASSERT_STATE(ApplicationState::RequestingLoginAfterSignup); @@ -389,7 +404,7 @@ void LauncherState::login(QString username, QString password, QString displayNam auto request = new LoginRequest(); - connect(request, &LoginRequest::finished, this, [this, request]() { + connect(request, &LoginRequest::finished, this, [this, request, username]() { ASSERT_STATE(ApplicationState::RequestingLogin); request->deleteLater(); @@ -404,6 +419,8 @@ void LauncherState::login(QString username, QString password, QString displayNam return; } + _lastUsedUsername = username; + _config.lastLogin = username; _config.loggedIn = true; _loginResponse = request->getToken(); _loginTokenResponse = request->getRawToken(); @@ -722,8 +739,9 @@ void LauncherState::launchClient() { QJsonDocument doc = QJsonDocument::fromJson(configFile.readAll()); doc.setObject({ { configHomeLocationKey, _config.homeLocation }, + { configLastLoginKey, _config.lastLogin }, { configLoggedInKey, _config.loggedIn }, - { configLauncherPathKey, _config.launcherPath }, + { configLauncherPathKey, getLauncherFilePath() }, }); configFile.write(doc.toJson()); } diff --git a/launchers/qt/src/LauncherState.h b/launchers/qt/src/LauncherState.h index 7d902417ac..7cbb09d237 100644 --- a/launchers/qt/src/LauncherState.h +++ b/launchers/qt/src/LauncherState.h @@ -13,6 +13,7 @@ #include "BuildsRequest.h" struct LauncherConfig { + QString lastLogin{ "" }; QString launcherPath{ "" }; bool loggedIn{ false }; QString homeLocation{ "" }; @@ -28,6 +29,7 @@ class LauncherState : public QObject { Q_PROPERTY(QString lastLoginErrorMessage READ getLastLoginErrorMessage NOTIFY lastLoginErrorMessageChanged) Q_PROPERTY(QString lastSignupErrorMessage READ getLastSignupErrorMessage NOTIFY lastSignupErrorMessageChanged) Q_PROPERTY(QString buildVersion READ getBuildVersion) + Q_PROPERTY(QString lastUsedUsername READ getLastUsedUsername) public: LauncherState(); @@ -94,6 +96,7 @@ public: QString getLastSignupErrorMessage() const { return _lastSignupErrorMessage; } QString getBuildVersion() { return QString(LAUNCHER_BUILD_VERSION); } + QString getLastUsedUsername() const { return _lastUsedUsername; } void setApplicationStateError(QString errorMessage); void setApplicationState(ApplicationState state); @@ -174,6 +177,7 @@ private: SignupRequest::Error _lastSignupError{ SignupRequest::Error::None }; QString _lastLoginErrorMessage{ "" }; QString _lastSignupErrorMessage{ "" }; + QString _lastUsedUsername; QString _displayName; QString _applicationErrorMessage; QString _currentClientVersion;