mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-21 20:27:45 +00:00
Add back auto login functionality
This commit is contained in:
parent
90a5ffc6c8
commit
201f4df179
10 changed files with 150 additions and 7 deletions
|
@ -47,6 +47,7 @@ qt_target_qml_sources(astra
|
||||||
QML_FILES
|
QML_FILES
|
||||||
ui/Components/FormFileDelegate.qml
|
ui/Components/FormFileDelegate.qml
|
||||||
ui/Components/FormFolderDelegate.qml
|
ui/Components/FormFolderDelegate.qml
|
||||||
|
ui/Pages/AutoLoginPage.qml
|
||||||
ui/Pages/BrowserPage.qml
|
ui/Pages/BrowserPage.qml
|
||||||
ui/Pages/LoginPage.qml
|
ui/Pages/LoginPage.qml
|
||||||
ui/Pages/MainPage.qml
|
ui/Pages/MainPage.qml
|
||||||
|
|
|
@ -32,5 +32,7 @@ SPDX-License-Identifier: CC0-1.0
|
||||||
<entry name="SquareEnixLoginServer" type="String">
|
<entry name="SquareEnixLoginServer" type="String">
|
||||||
<default>square-enix.com</default>
|
<default>square-enix.com</default>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry name="AutoLoginProfile" type="String">
|
||||||
|
</entry>
|
||||||
</group>
|
</group>
|
||||||
</kcfg>
|
</kcfg>
|
||||||
|
|
|
@ -74,6 +74,7 @@ class LauncherCore : public QObject
|
||||||
Q_PROPERTY(QString squareEnixLoginServer READ squareEnixLoginServer WRITE setSquareEnixLoginServer NOTIFY squareEnixLoginServerChanged)
|
Q_PROPERTY(QString squareEnixLoginServer READ squareEnixLoginServer WRITE setSquareEnixLoginServer NOTIFY squareEnixLoginServerChanged)
|
||||||
Q_PROPERTY(Headline *headline READ headline NOTIFY newsChanged)
|
Q_PROPERTY(Headline *headline READ headline NOTIFY newsChanged)
|
||||||
Q_PROPERTY(Profile *currentProfile READ currentProfile WRITE setCurrentProfile NOTIFY currentProfileChanged)
|
Q_PROPERTY(Profile *currentProfile READ currentProfile WRITE setCurrentProfile NOTIFY currentProfileChanged)
|
||||||
|
Q_PROPERTY(Profile *autoLoginProfile READ autoLoginProfile WRITE setAutoLoginProfile NOTIFY autoLoginProfileChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LauncherCore();
|
LauncherCore();
|
||||||
|
@ -100,7 +101,7 @@ public:
|
||||||
* The launcher will still warn the user about any possible errors, however the call site will need to check the
|
* The launcher will still warn the user about any possible errors, however the call site will need to check the
|
||||||
* result to see whether they need to "reset" or show a failed state or not.
|
* result to see whether they need to "reset" or show a failed state or not.
|
||||||
*/
|
*/
|
||||||
bool autoLogin(Profile &settings);
|
Q_INVOKABLE void autoLogin(Profile *profile);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Launches the game using the provided authentication.
|
* Launches the game using the provided authentication.
|
||||||
|
@ -139,6 +140,10 @@ public:
|
||||||
[[nodiscard]] QString squareEnixLoginServer() const;
|
[[nodiscard]] QString squareEnixLoginServer() const;
|
||||||
void setSquareEnixLoginServer(const QString &value);
|
void setSquareEnixLoginServer(const QString &value);
|
||||||
|
|
||||||
|
[[nodiscard]] QString autoLoginProfileName() const;
|
||||||
|
[[nodiscard]] Profile *autoLoginProfile() const;
|
||||||
|
void setAutoLoginProfile(Profile *value);
|
||||||
|
|
||||||
Q_INVOKABLE GameInstaller *createInstaller(Profile *profile);
|
Q_INVOKABLE GameInstaller *createInstaller(Profile *profile);
|
||||||
Q_INVOKABLE CompatibilityToolInstaller *createCompatInstaller();
|
Q_INVOKABLE CompatibilityToolInstaller *createCompatInstaller();
|
||||||
|
|
||||||
|
@ -177,6 +182,7 @@ signals:
|
||||||
void stageDeterminate(int min, int max, int value);
|
void stageDeterminate(int min, int max, int value);
|
||||||
void newsChanged();
|
void newsChanged();
|
||||||
void currentProfileChanged();
|
void currentProfileChanged();
|
||||||
|
void autoLoginProfileChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QCoro::Task<> beginLogin(LoginInformation &info);
|
QCoro::Task<> beginLogin(LoginInformation &info);
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
Q_INVOKABLE Profile *getProfile(int index);
|
Q_INVOKABLE Profile *getProfile(int index);
|
||||||
|
Profile *getProfileByUUID(const QString &uuid);
|
||||||
|
|
||||||
int getProfileIndex(const QString &name);
|
int getProfileIndex(const QString &name);
|
||||||
Q_INVOKABLE Profile *addProfile();
|
Q_INVOKABLE Profile *addProfile();
|
||||||
|
|
|
@ -448,12 +448,9 @@ void LauncherCore::login(Profile *profile, const QString &username, const QStrin
|
||||||
beginLogin(*loginInformation);
|
beginLogin(*loginInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LauncherCore::autoLogin(Profile &profile)
|
void LauncherCore::autoLogin(Profile *profile)
|
||||||
{
|
{
|
||||||
// TODO: when login fails, we need some way to propagate this back? or not?
|
login(profile, profile->account()->name(), profile->account()->getPassword(), profile->account()->useOTP() ? profile->account()->getOTP() : QString());
|
||||||
login(&profile, profile.account()->name(), profile.account()->getPassword(), profile.account()->getOTP());
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GameInstaller *LauncherCore::createInstaller(Profile *profile)
|
GameInstaller *LauncherCore::createInstaller(Profile *profile)
|
||||||
|
@ -585,6 +582,36 @@ void LauncherCore::setSquareEnixLoginServer(const QString &value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QString LauncherCore::autoLoginProfileName() const
|
||||||
|
{
|
||||||
|
return Config::autoLoginProfile();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] Profile *LauncherCore::autoLoginProfile() const
|
||||||
|
{
|
||||||
|
if (Config::autoLoginProfile().isEmpty()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return m_profileManager->getProfileByUUID(Config::autoLoginProfile());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LauncherCore::setAutoLoginProfile(Profile *profile)
|
||||||
|
{
|
||||||
|
if (profile == nullptr) {
|
||||||
|
Config::setAutoLoginProfile({});
|
||||||
|
Config::self()->save();
|
||||||
|
Q_EMIT autoLoginProfileChanged();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto uuid = profile->uuid();
|
||||||
|
if (uuid != Config::autoLoginProfile()) {
|
||||||
|
Config::setAutoLoginProfile(uuid);
|
||||||
|
Config::self()->save();
|
||||||
|
Q_EMIT autoLoginProfileChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LauncherCore::refreshNews()
|
void LauncherCore::refreshNews()
|
||||||
{
|
{
|
||||||
fetchNews();
|
fetchNews();
|
||||||
|
|
|
@ -28,6 +28,16 @@ int ProfileManager::getProfileIndex(const QString &name)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Profile *ProfileManager::getProfileByUUID(const QString &uuid)
|
||||||
|
{
|
||||||
|
for (auto &m_profile : m_profiles) {
|
||||||
|
if (m_profile->uuid() == uuid)
|
||||||
|
return m_profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
Profile *ProfileManager::addProfile()
|
Profile *ProfileManager::addProfile()
|
||||||
{
|
{
|
||||||
auto newProfile = new Profile(m_launcher, QUuid::createUuid().toString(), this);
|
auto newProfile = new Profile(m_launcher, QUuid::createUuid().toString(), this);
|
||||||
|
@ -91,6 +101,7 @@ void ProfileManager::load()
|
||||||
auto config = KSharedConfig::openStateConfig();
|
auto config = KSharedConfig::openStateConfig();
|
||||||
for (const auto &id : config->groupList()) {
|
for (const auto &id : config->groupList()) {
|
||||||
if (id.contains(QLatin1String("profile-"))) {
|
if (id.contains(QLatin1String("profile-"))) {
|
||||||
|
qInfo() << "Adding profile" << id;
|
||||||
auto profile = new Profile(m_launcher, QString(id).remove(QLatin1String("profile-")), this);
|
auto profile = new Profile(m_launcher, QString(id).remove(QLatin1String("profile-")), this);
|
||||||
insertProfile(profile);
|
insertProfile(profile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,8 @@ QCoro::Task<> SquareLauncher::login(const LoginInformation &info)
|
||||||
|
|
||||||
const auto [stored, referer] = *storedResult;
|
const auto [stored, referer] = *storedResult;
|
||||||
|
|
||||||
|
qInfo() << "Performing oauth...";
|
||||||
|
|
||||||
QUrlQuery postData;
|
QUrlQuery postData;
|
||||||
postData.addQueryItem(QStringLiteral("_STORED_"), stored);
|
postData.addQueryItem(QStringLiteral("_STORED_"), stored);
|
||||||
postData.addQueryItem(QStringLiteral("sqexid"), info.username);
|
postData.addQueryItem(QStringLiteral("sqexid"), info.username);
|
||||||
|
|
|
@ -46,10 +46,19 @@ Kirigami.ApplicationWindow {
|
||||||
profile: LauncherCore.currentProfile
|
profile: LauncherCore.currentProfile
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
pageStack.layers.replace(Qt.createComponent("zone.xiv.astra", "MainPage"))
|
if (LauncherCore.autoLoginProfile) {
|
||||||
|
pageStack.layers.replace(Qt.createComponent("zone.xiv.astra", "AutoLoginPage"))
|
||||||
|
} else {
|
||||||
|
pageStack.layers.replace(Qt.createComponent("zone.xiv.astra", "MainPage"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cancelAutoLogin() {
|
||||||
|
pageStack.layers.clear();
|
||||||
|
pageStack.layers.replace(Qt.createComponent("zone.xiv.astra", "MainPage"));
|
||||||
|
}
|
||||||
|
|
||||||
function pushDialogLayer(url) {
|
function pushDialogLayer(url) {
|
||||||
if (LauncherCore.isSteamDeck) {
|
if (LauncherCore.isSteamDeck) {
|
||||||
pageStack.layers.push(url)
|
pageStack.layers.push(url)
|
||||||
|
|
44
launcher/ui/Pages/AutoLoginPage.qml
Normal file
44
launcher/ui/Pages/AutoLoginPage.qml
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import QtQuick
|
||||||
|
import QtQuick.Controls as QQC2
|
||||||
|
|
||||||
|
import org.kde.kirigami as Kirigami
|
||||||
|
|
||||||
|
import zone.xiv.astra
|
||||||
|
|
||||||
|
Kirigami.Page {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
title: i18n("Auto Login")
|
||||||
|
|
||||||
|
Kirigami.LoadingPlaceholder {
|
||||||
|
id: placeholderMessage
|
||||||
|
|
||||||
|
anchors.centerIn: parent
|
||||||
|
|
||||||
|
text: i18n("Logging in...")
|
||||||
|
|
||||||
|
helpfulAction: Kirigami.Action {
|
||||||
|
icon.name: "Cancel"
|
||||||
|
text: "Cancel"
|
||||||
|
enabled: autoLoginTimer.running
|
||||||
|
onTriggered: {
|
||||||
|
autoLoginTimer.stop();
|
||||||
|
applicationWindow().cancelAutoLogin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: autoLoginTimer
|
||||||
|
|
||||||
|
interval: 5000
|
||||||
|
running: true
|
||||||
|
onTriggered: {
|
||||||
|
LauncherCore.autoLogin(LauncherCore.autoLoginProfile);
|
||||||
|
pageStack.layers.push(Qt.createComponent("zone.xiv.astra", "StatusPage"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,9 @@
|
||||||
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import QtQuick
|
||||||
|
import QtQuick.Controls as QQC2
|
||||||
|
|
||||||
import org.kde.kirigamiaddons.formcard as FormCard
|
import org.kde.kirigamiaddons.formcard as FormCard
|
||||||
|
|
||||||
import zone.xiv.astra
|
import zone.xiv.astra
|
||||||
|
@ -13,6 +16,43 @@ FormCard.FormCardPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
FormCard.FormCard {
|
FormCard.FormCard {
|
||||||
|
FormCard.FormButtonDelegate {
|
||||||
|
text: i18n("Auto-login Profile")
|
||||||
|
description: LauncherCore.autoLoginProfile ? LauncherCore.autoLoginProfile.name : i18n("Disabled")
|
||||||
|
|
||||||
|
QQC2.Menu {
|
||||||
|
id: profileMenu
|
||||||
|
|
||||||
|
QQC2.MenuItem {
|
||||||
|
text: "Disabled"
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
LauncherCore.autoLoginProfile = null;
|
||||||
|
profileMenu.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Repeater {
|
||||||
|
model: LauncherCore.profileManager
|
||||||
|
|
||||||
|
QQC2.MenuItem {
|
||||||
|
required property var profile
|
||||||
|
|
||||||
|
text: profile.name
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
LauncherCore.autoLoginProfile = profile;
|
||||||
|
profileMenu.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onClicked: profileMenu.popup()
|
||||||
|
}
|
||||||
|
|
||||||
|
FormCard.FormDelegateSeparator {}
|
||||||
|
|
||||||
FormCard.FormCheckDelegate {
|
FormCard.FormCheckDelegate {
|
||||||
id: closeAstraDelegate
|
id: closeAstraDelegate
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue