mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-20 11:47:46 +00:00
Add autologin and default-profile options
This commit is contained in:
parent
eaacd3303a
commit
80306d65fb
2 changed files with 63 additions and 2 deletions
|
@ -42,7 +42,7 @@ struct ProfileSettings {
|
|||
};
|
||||
|
||||
struct LoginInformation {
|
||||
ProfileSettings* settings = nullptr;
|
||||
const ProfileSettings* settings = nullptr;
|
||||
|
||||
QString username, password, oneTimePassword;
|
||||
};
|
||||
|
|
63
src/main.cpp
63
src/main.cpp
|
@ -3,6 +3,10 @@
|
|||
|
||||
#include <QApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <keychain.h>
|
||||
|
||||
#include "sapphirelauncher.h"
|
||||
#include "squareboot.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
|
@ -26,10 +30,67 @@ int main(int argc, char* argv[]) {
|
|||
QCommandLineOption noguiOption("nogui", "Don't open a main window.");
|
||||
parser.addOption(noguiOption);
|
||||
|
||||
QCommandLineOption autologinOption("autologin", "Auto-login with the default profile. This requires the profile to have remember username/password enabled!");
|
||||
parser.addOption(autologinOption);
|
||||
|
||||
QCommandLineOption profileOption("default-profile", "Profile to use for default profile and autologin.", "profile");
|
||||
parser.addOption(profileOption);
|
||||
|
||||
parser.process(app);
|
||||
|
||||
if(parser.isSet(profileOption)) {
|
||||
c.defaultProfileIndex = c.getProfileIndex(parser.value(profileOption));
|
||||
|
||||
if(c.defaultProfileIndex == -1) {
|
||||
qInfo() << "The profile \"" << parser.value(profileOption) << "\" does not exist!";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(parser.isSet(autologinOption)) {
|
||||
const auto profile = c.getProfile(c.defaultProfileIndex);
|
||||
|
||||
if(!profile.rememberUsername || !profile.rememberPassword) {
|
||||
qInfo() << "Profile does not have a username and/or password saved, autologin disabled.";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto loop = new QEventLoop();
|
||||
QString username, password;
|
||||
|
||||
auto usernameJob = new QKeychain::ReadPasswordJob("LauncherWindow");
|
||||
usernameJob->setKey(profile.name + "-username");
|
||||
usernameJob->start();
|
||||
|
||||
c.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();
|
||||
|
||||
c.connect(passwordJob, &QKeychain::ReadPasswordJob::finished, [loop, passwordJob, &password](QKeychain::Job* j) {
|
||||
password = passwordJob->textData();
|
||||
loop->quit();
|
||||
});
|
||||
|
||||
loop->exec();
|
||||
|
||||
auto info = LoginInformation{&profile, username, password, ""};
|
||||
|
||||
if(profile.isSapphire) {
|
||||
c.sapphireLauncher->login(profile.lobbyURL, info);
|
||||
} else {
|
||||
c.squareBoot->bootCheck(info);
|
||||
}
|
||||
}
|
||||
|
||||
LauncherWindow w(c);
|
||||
if(!parser.isSet(noguiOption)) {
|
||||
LauncherWindow w(c);
|
||||
w.show();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue