diff --git a/launcher/core/include/launchercore.h b/launcher/core/include/launchercore.h index 4d4ea4e..4a1792b 100755 --- a/launcher/core/include/launchercore.h +++ b/launcher/core/include/launchercore.h @@ -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; diff --git a/launcher/core/src/launchercore.cpp b/launcher/core/src/launchercore.cpp index 28924ed..fb22f37 100755 --- a/launcher/core/src/launchercore.cpp +++ b/launcher/core/src/launchercore.cpp @@ -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); diff --git a/launcher/desktop/CMakeLists.txt b/launcher/desktop/CMakeLists.txt index ce7d35e..ee94b4c 100644 --- a/launcher/desktop/CMakeLists.txt +++ b/launcher/desktop/CMakeLists.txt @@ -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) diff --git a/launcher/desktop/include/autologinwindow.h b/launcher/desktop/include/autologinwindow.h new file mode 100644 index 0000000..ded82a5 --- /dev/null +++ b/launcher/desktop/include/autologinwindow.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +class LauncherCore; +class LauncherWindow; +struct ProfileSettings; + +class AutoLoginWindow : public QDialog { + Q_OBJECT +public: + AutoLoginWindow(ProfileSettings& settings, LauncherCore& core, QWidget* parent = nullptr); + +signals: + void loginCanceled(); +}; diff --git a/launcher/desktop/include/desktopinterface.h b/launcher/desktop/include/desktopinterface.h index 41b8234..c1d3e67 100644 --- a/launcher/desktop/include/desktopinterface.h +++ b/launcher/desktop/include/desktopinterface.h @@ -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; }; \ No newline at end of file diff --git a/launcher/desktop/include/settingswindow.h b/launcher/desktop/include/settingswindow.h index ff5dddf..d752257 100644 --- a/launcher/desktop/include/settingswindow.h +++ b/launcher/desktop/include/settingswindow.h @@ -65,6 +65,7 @@ private: QComboBox* gameLicenseBox = nullptr; QCheckBox* freeTrialBox = nullptr; QCheckBox* useOneTimePassword = nullptr; + QCheckBox* autoLoginBox = nullptr; // dalamud QCheckBox* enableDalamudBox = nullptr; diff --git a/launcher/desktop/src/autologinwindow.cpp b/launcher/desktop/src/autologinwindow.cpp new file mode 100644 index 0000000..20c87d4 --- /dev/null +++ b/launcher/desktop/src/autologinwindow.cpp @@ -0,0 +1,83 @@ +#include "autologinwindow.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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); +} \ No newline at end of file diff --git a/launcher/desktop/src/desktopinterface.cpp b/launcher/desktop/src/desktopinterface.cpp index dae19ec..402b936 100644 --- a/launcher/desktop/src/desktopinterface.cpp +++ b/launcher/desktop/src/desktopinterface.cpp @@ -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(); + } } \ No newline at end of file diff --git a/launcher/desktop/src/settingswindow.cpp b/launcher/desktop/src/settingswindow.cpp index 24cc753..b67ea7b 100644 --- a/launcher/desktop/src/settingswindow.cpp +++ b/launcher/desktop/src/settingswindow.cpp @@ -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) {