mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-20 19:57:45 +00:00
Add a basic auto-login window
Soon, you'll be able to store an OTP secret with Astra :-) Also, the cancel button is broken ATM, so you have to manually turn the feature off in the config.
This commit is contained in:
parent
0eb75d0d88
commit
d28ed71e87
9 changed files with 132 additions and 4 deletions
|
@ -92,6 +92,7 @@ public:
|
|||
QString lobbyURL;
|
||||
bool rememberUsername = false, rememberPassword = false;
|
||||
bool useOneTimePassword = false;
|
||||
bool autoLogin = false;
|
||||
|
||||
GameLicense license = GameLicense::WindowsStandalone;
|
||||
bool isFreeTrial = false;
|
||||
|
|
|
@ -420,6 +420,7 @@ void LauncherCore::readInitialInformation() {
|
|||
profile->useOneTimePassword = settings.value("useOneTimePassword", defaultSettings.useOneTimePassword).toBool();
|
||||
profile->license = (GameLicense)settings.value("license", (int)defaultSettings.license).toInt();
|
||||
profile->isFreeTrial = settings.value("isFreeTrial", defaultSettings.isFreeTrial).toBool();
|
||||
profile->autoLogin = settings.value("autoLogin", defaultSettings.autoLogin).toBool();
|
||||
|
||||
profile->useDX9 = settings.value("useDX9", defaultSettings.useDX9).toBool();
|
||||
|
||||
|
@ -631,6 +632,7 @@ void LauncherCore::saveSettings() {
|
|||
settings.setValue("useOneTimePassword", profile->useOneTimePassword);
|
||||
settings.setValue("license", (int)profile->license);
|
||||
settings.setValue("isFreeTrial", profile->isFreeTrial);
|
||||
settings.setValue("autoLogin", profile->autoLogin);
|
||||
|
||||
settings.setValue("enableDalamud", profile->dalamud.enabled);
|
||||
settings.setValue("dalamudOptOut", profile->dalamud.optOutOfMbCollection);
|
||||
|
|
|
@ -5,7 +5,8 @@ set(HEADERS
|
|||
include/desktopinterface.h
|
||||
include/gamescopesettingswindow.h
|
||||
include/launcherwindow.h
|
||||
include/settingswindow.h)
|
||||
include/settingswindow.h
|
||||
include/autologinwindow.h)
|
||||
|
||||
set(SRC
|
||||
src/aboutwindow.cpp
|
||||
|
@ -14,7 +15,8 @@ set(SRC
|
|||
src/desktopinterface.cpp
|
||||
src/gamescopesettingswindow.cpp
|
||||
src/launcherwindow.cpp
|
||||
src/settingswindow.cpp)
|
||||
src/settingswindow.cpp
|
||||
src/autologinwindow.cpp)
|
||||
|
||||
add_library(astra_desktop STATIC ${HEADERS} ${SRC})
|
||||
target_include_directories(astra_desktop PUBLIC include)
|
||||
|
|
16
launcher/desktop/include/autologinwindow.h
Normal file
16
launcher/desktop/include/autologinwindow.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class LauncherCore;
|
||||
class LauncherWindow;
|
||||
struct ProfileSettings;
|
||||
|
||||
class AutoLoginWindow : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AutoLoginWindow(ProfileSettings& settings, LauncherCore& core, QWidget* parent = nullptr);
|
||||
|
||||
signals:
|
||||
void loginCanceled();
|
||||
};
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "launcherwindow.h"
|
||||
#include "autologinwindow.h"
|
||||
|
||||
/*
|
||||
* The desktop, mouse and keyboard-driven interface for Astra. Primarily meant
|
||||
|
@ -12,4 +13,5 @@ public:
|
|||
|
||||
private:
|
||||
LauncherWindow* window = nullptr;
|
||||
AutoLoginWindow* autoLoginWindow = nullptr;
|
||||
};
|
|
@ -65,6 +65,7 @@ private:
|
|||
QComboBox* gameLicenseBox = nullptr;
|
||||
QCheckBox* freeTrialBox = nullptr;
|
||||
QCheckBox* useOneTimePassword = nullptr;
|
||||
QCheckBox* autoLoginBox = nullptr;
|
||||
|
||||
// dalamud
|
||||
QCheckBox* enableDalamudBox = nullptr;
|
||||
|
|
83
launcher/desktop/src/autologinwindow.cpp
Normal file
83
launcher/desktop/src/autologinwindow.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
#include "autologinwindow.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QDesktopServices>
|
||||
#include <QFileDialog>
|
||||
#include <QFormLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include <QPushButton>
|
||||
#include <QSpinBox>
|
||||
#include <QToolTip>
|
||||
#include <keychain.h>
|
||||
|
||||
#include "launchercore.h"
|
||||
#include "launcherwindow.h"
|
||||
#include "sapphirelauncher.h"
|
||||
|
||||
AutoLoginWindow::AutoLoginWindow(ProfileSettings& profile, LauncherCore& core, QWidget* parent)
|
||||
: QDialog(parent) {
|
||||
setWindowTitle("Auto Login");
|
||||
setWindowModality(Qt::WindowModality::ApplicationModal);
|
||||
|
||||
auto mainLayout = new QFormLayout(this);
|
||||
setLayout(mainLayout);
|
||||
|
||||
auto label = new QLabel("Currently logging in...");
|
||||
mainLayout->addWidget(label);
|
||||
|
||||
auto cancelButton = new QPushButton("Cancel");
|
||||
connect(cancelButton, &QPushButton::clicked, this, &AutoLoginWindow::loginCanceled);
|
||||
mainLayout->addWidget(cancelButton);
|
||||
|
||||
auto autologinTimer = new QTimer();
|
||||
connect(autologinTimer, &QTimer::timeout, [&] {
|
||||
qDebug() << "logging in!";
|
||||
|
||||
// TODO: this is the second place where I have implemented this. this is a good idea to abstract, maybe? :-)
|
||||
auto loop = new QEventLoop();
|
||||
QString username, password;
|
||||
|
||||
auto usernameJob = new QKeychain::ReadPasswordJob("LauncherWindow");
|
||||
usernameJob->setKey(profile.name + "-username");
|
||||
usernameJob->start();
|
||||
|
||||
core.connect(
|
||||
usernameJob, &QKeychain::ReadPasswordJob::finished, [loop, usernameJob, &username](QKeychain::Job* j) {
|
||||
username = usernameJob->textData();
|
||||
loop->quit();
|
||||
});
|
||||
|
||||
loop->exec();
|
||||
|
||||
auto passwordJob = new QKeychain::ReadPasswordJob("LauncherWindow");
|
||||
passwordJob->setKey(profile.name + "-password");
|
||||
passwordJob->start();
|
||||
|
||||
core.connect(
|
||||
passwordJob, &QKeychain::ReadPasswordJob::finished, [loop, passwordJob, &password](QKeychain::Job* j) {
|
||||
password = passwordJob->textData();
|
||||
loop->quit();
|
||||
});
|
||||
|
||||
loop->exec();
|
||||
|
||||
auto info = new LoginInformation();
|
||||
info->settings = &profile;
|
||||
info->username = username;
|
||||
info->password = password;
|
||||
|
||||
if (profile.isSapphire) {
|
||||
core.sapphireLauncher->login(profile.lobbyURL, *info);
|
||||
} else {
|
||||
core.squareBoot->bootCheck(*info);
|
||||
}
|
||||
});
|
||||
connect(this, &AutoLoginWindow::loginCanceled, [autologinTimer] {
|
||||
autologinTimer->stop();
|
||||
});
|
||||
autologinTimer->start(5000);
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
#include "desktopinterface.h"
|
||||
#include "autologinwindow.h"
|
||||
#include "gameinstaller.h"
|
||||
|
||||
DesktopInterface::DesktopInterface(LauncherCore& core) {
|
||||
window = new LauncherWindow(core);
|
||||
window->show();
|
||||
|
||||
auto& defaultProfile = core.getProfile(core.defaultProfileIndex);
|
||||
|
||||
|
@ -22,7 +22,7 @@ DesktopInterface::DesktopInterface(LauncherCore& core) {
|
|||
messageBox->setWindowModality(Qt::WindowModal);
|
||||
|
||||
auto installButton = messageBox->addButton("Install Game", QMessageBox::YesRole);
|
||||
core.connect(installButton, &QPushButton::clicked, [&core, messageBox] {
|
||||
QObject::connect(installButton, &QPushButton::clicked, [&core, messageBox] {
|
||||
installGame(core, core.getProfile(core.defaultProfileIndex), [messageBox, &core] {
|
||||
core.readGameVersion();
|
||||
|
||||
|
@ -50,4 +50,15 @@ DesktopInterface::DesktopInterface(LauncherCore& core) {
|
|||
messageBox->exec();
|
||||
}
|
||||
#endif
|
||||
|
||||
if(defaultProfile.autoLogin) {
|
||||
autoLoginWindow = new AutoLoginWindow(defaultProfile, core);
|
||||
QObject::connect(autoLoginWindow, &AutoLoginWindow::loginCanceled, [this] {
|
||||
autoLoginWindow->hide();
|
||||
window->show();
|
||||
});
|
||||
autoLoginWindow->show();
|
||||
} else {
|
||||
window->show();
|
||||
}
|
||||
}
|
|
@ -264,6 +264,7 @@ void SettingsWindow::reloadControls() {
|
|||
} else {
|
||||
useOneTimePassword->setToolTip("");
|
||||
}
|
||||
autoLoginBox->setChecked(profile.autoLogin);
|
||||
|
||||
gameLicenseBox->setCurrentIndex((int)profile.license);
|
||||
gameLicenseBox->setEnabled(!profile.isSapphire);
|
||||
|
@ -436,6 +437,15 @@ void SettingsWindow::setupLoginTab(QFormLayout& layout) {
|
|||
this->window.reloadControls();
|
||||
});
|
||||
layout.addRow("Use One-Time Password", useOneTimePassword);
|
||||
|
||||
autoLoginBox = new QCheckBox();
|
||||
connect(autoLoginBox, &QCheckBox::stateChanged, [=](int) {
|
||||
getCurrentProfile().autoLogin = autoLoginBox->isChecked();
|
||||
|
||||
this->core.saveSettings();
|
||||
this->window.reloadControls();
|
||||
});
|
||||
layout.addRow("Auto-Login", autoLoginBox);
|
||||
}
|
||||
|
||||
void SettingsWindow::setupWineTab(QFormLayout& layout) {
|
||||
|
|
Loading…
Add table
Reference in a new issue