mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2025-10-18 08:27:53 +00:00
[frontend, web] refactor: web service frontend rewrite (#221)
- Automatic verification based on regex - Token generation button - Removed unneeded links - public lobby creation [android] Signed-off-by: crueter <swurl@swurl.xyz> Co-authored-by: Aleksandr Popovich <alekpopo@pm.me> Co-authored-by: Aleksandr Popovich <alekpopo@proton.me> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/221 Co-authored-by: crueter <swurl@swurl.xyz> Co-committed-by: crueter <swurl@swurl.xyz>
This commit is contained in:
parent
2fe728766e
commit
94c66f98bf
34 changed files with 1985 additions and 327 deletions
|
@ -1,44 +1,52 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2017 Citra Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "yuzu/configuration/configure_web.h"
|
||||
#include <QIcon>
|
||||
#include <QMessageBox>
|
||||
|
||||
#if QT_VERSION_MAJOR >= 6
|
||||
#include <QRegularExpressionValidator>
|
||||
#else
|
||||
#include <QRegExpValidator>
|
||||
#endif
|
||||
|
||||
#include <QtConcurrent/QtConcurrentRun>
|
||||
#include "common/settings.h"
|
||||
#include "ui_configure_web.h"
|
||||
#include "yuzu/configuration/configure_web.h"
|
||||
#include "yuzu/uisettings.h"
|
||||
|
||||
// static constexpr char token_delimiter{':'};
|
||||
|
||||
// static std::string GenerateDisplayToken(const std::string& username, const std::string& token) {
|
||||
// if (username.empty() || token.empty()) {
|
||||
// return {};
|
||||
// }
|
||||
|
||||
// const std::string unencoded_display_token{username + token_delimiter + token};
|
||||
// QByteArray b{unencoded_display_token.c_str()};
|
||||
// QByteArray b64 = b.toBase64();
|
||||
// return b64.toStdString();
|
||||
// }
|
||||
|
||||
// static std::string UsernameFromDisplayToken(const std::string& display_token) {
|
||||
// const std::string unencoded_display_token{
|
||||
// QByteArray::fromBase64(display_token.c_str()).toStdString()};
|
||||
// return unencoded_display_token.substr(0, unencoded_display_token.find(token_delimiter));
|
||||
// }
|
||||
|
||||
// static std::string TokenFromDisplayToken(const std::string& display_token) {
|
||||
// const std::string unencoded_display_token{
|
||||
// QByteArray::fromBase64(display_token.c_str()).toStdString()};
|
||||
// return unencoded_display_token.substr(unencoded_display_token.find(token_delimiter) + 1);
|
||||
// }
|
||||
|
||||
ConfigureWeb::ConfigureWeb(QWidget* parent)
|
||||
: QWidget(parent), ui(std::make_unique<Ui::ConfigureWeb>()) {
|
||||
: QWidget(parent)
|
||||
, ui(std::make_unique<Ui::ConfigureWeb>())
|
||||
, m_rng{QRandomGenerator::system()}
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->button_verify_login, &QPushButton::clicked, this, &ConfigureWeb::VerifyLogin);
|
||||
connect(&verify_watcher, &QFutureWatcher<bool>::finished, this, &ConfigureWeb::OnLoginVerified);
|
||||
|
||||
QString user_regex = QStringLiteral(".{4,20}");
|
||||
QString token_regex = QStringLiteral("[a-z]{48}");
|
||||
|
||||
#if QT_VERSION_MAJOR >= 6
|
||||
QRegularExpressionValidator *username_validator = new QRegularExpressionValidator(this);
|
||||
QRegularExpressionValidator *token_validator = new QRegularExpressionValidator(this);
|
||||
|
||||
username_validator->setRegularExpression(QRegularExpression(user_regex));
|
||||
token_validator->setRegularExpression(QRegularExpression(token_regex));
|
||||
#else
|
||||
QRegExpValidator *username_validator = new QRegExpValidator(this);
|
||||
QRegExpValidator *token_validator = new QRegExpValidator(this);
|
||||
|
||||
username_validator->setRegExp(QRegExp(user_regex));
|
||||
token_validator->setRegExp(QRegExp(token_regex));
|
||||
#endif
|
||||
|
||||
ui->edit_username->setValidator(username_validator);
|
||||
ui->edit_token->setValidator(token_validator);
|
||||
|
||||
connect(ui->button_generate, &QPushButton::clicked, this, &ConfigureWeb::GenerateToken);
|
||||
|
||||
#ifndef USE_DISCORD_PRESENCE
|
||||
ui->discord_group->setVisible(false);
|
||||
|
@ -60,87 +68,61 @@ void ConfigureWeb::changeEvent(QEvent* event) {
|
|||
|
||||
void ConfigureWeb::RetranslateUI() {
|
||||
ui->retranslateUi(this);
|
||||
|
||||
ui->web_signup_link->setText(
|
||||
tr("<a href='https://profile.yuzu-emu.org/'><span style=\"text-decoration: underline; "
|
||||
"color:#039be5;\">Sign up</span></a>"));
|
||||
|
||||
ui->web_token_info_link->setText(
|
||||
tr("<a href='https://evilperson1337.notion.site/Hosting-a-Room-Inside-of-Eden-20457c2edaf680108abac6215a79acdb'><span style=\"text-decoration: "
|
||||
"underline; color:#039be5;\">What is my token?</span></a>"));
|
||||
}
|
||||
|
||||
void ConfigureWeb::SetConfiguration() {
|
||||
ui->web_credentials_disclaimer->setWordWrap(true);
|
||||
connect(ui->edit_username, &QLineEdit::textChanged, this, &ConfigureWeb::VerifyLogin);
|
||||
connect(ui->edit_token, &QLineEdit::textChanged, this, &ConfigureWeb::VerifyLogin);
|
||||
|
||||
ui->web_signup_link->setOpenExternalLinks(true);
|
||||
ui->web_token_info_link->setOpenExternalLinks(true);
|
||||
ui->edit_username->setText(QString::fromStdString(Settings::values.eden_username.GetValue()));
|
||||
ui->edit_token->setText(QString::fromStdString(Settings::values.eden_token.GetValue()));
|
||||
|
||||
ui->edit_username->setText(QString::fromStdString(Settings::values.yuzu_username.GetValue()));
|
||||
ui->edit_token->setText(QString::fromStdString(Settings::values.yuzu_token.GetValue()));
|
||||
// ui->edit_token->setText(QString::fromStdString(GenerateDisplayToken(
|
||||
// Settings::values.yuzu_username.GetValue(), Settings::values.yuzu_token.GetValue())));
|
||||
|
||||
// Connect after setting the values, to avoid calling OnLoginChanged now
|
||||
connect(ui->edit_token, &QLineEdit::textChanged, this, &ConfigureWeb::OnLoginChanged);
|
||||
|
||||
user_verified = true;
|
||||
VerifyLogin();
|
||||
|
||||
ui->toggle_discordrpc->setChecked(UISettings::values.enable_discord_presence.GetValue());
|
||||
}
|
||||
|
||||
void ConfigureWeb::ApplyConfiguration() {
|
||||
UISettings::values.enable_discord_presence = ui->toggle_discordrpc->isChecked();
|
||||
Settings::values.yuzu_username = ui->edit_username->text().toStdString();
|
||||
Settings::values.yuzu_token = ui->edit_token->text().toStdString();
|
||||
void ConfigureWeb::GenerateToken() {
|
||||
constexpr size_t length = 48;
|
||||
QString set = QStringLiteral("abcdefghijklmnopqrstuvwxyz");
|
||||
QString result;
|
||||
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
size_t idx = m_rng->bounded(set.length());
|
||||
result.append(set.at(idx));
|
||||
}
|
||||
|
||||
ui->edit_token->setText(result);
|
||||
}
|
||||
|
||||
void ConfigureWeb::OnLoginChanged() {
|
||||
if (ui->edit_token->text().isEmpty()) {
|
||||
user_verified = true;
|
||||
// Empty = no icon
|
||||
ui->label_token_verified->setPixmap(QPixmap());
|
||||
ui->label_token_verified->setToolTip(QString());
|
||||
} else {
|
||||
user_verified = false;
|
||||
|
||||
// Show an info icon if it's been changed, clearer than showing failure
|
||||
const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("info")).pixmap(16);
|
||||
ui->label_token_verified->setPixmap(pixmap);
|
||||
ui->label_token_verified->setToolTip(
|
||||
tr("Unverified, please click Verify before saving configuration", "Tooltip"));
|
||||
}
|
||||
void ConfigureWeb::ApplyConfiguration() {
|
||||
UISettings::values.enable_discord_presence = ui->toggle_discordrpc->isChecked();
|
||||
Settings::values.eden_username = ui->edit_username->text().toStdString();
|
||||
Settings::values.eden_token = ui->edit_token->text().toStdString();
|
||||
}
|
||||
|
||||
void ConfigureWeb::VerifyLogin() {
|
||||
QMessageBox::warning(this,
|
||||
tr("Warning"),
|
||||
tr("Verification is currently nonfunctional, instead generate a random "
|
||||
"48-character string with only lowercase a-z."));
|
||||
// ui->button_verify_login->setDisabled(true);
|
||||
// ui->button_verify_login->setText(tr("Verifying..."));
|
||||
// ui->label_token_verified->setPixmap(QIcon::fromTheme(QStringLiteral("sync")).pixmap(16));
|
||||
// ui->label_token_verified->setToolTip(tr("Verifying..."));
|
||||
}
|
||||
const QPixmap checked = QIcon::fromTheme(QStringLiteral("checked")).pixmap(16);
|
||||
const QPixmap failed = QIcon::fromTheme(QStringLiteral("failed")).pixmap(16);
|
||||
|
||||
void ConfigureWeb::OnLoginVerified() {
|
||||
// ui->button_verify_login->setEnabled(true);
|
||||
// ui->button_verify_login->setText(tr("Verify"));
|
||||
// if (verify_watcher.result()) {
|
||||
// user_verified = true;
|
||||
const bool username_good = ui->edit_username->hasAcceptableInput();
|
||||
const bool token_good = ui->edit_token->hasAcceptableInput();
|
||||
|
||||
// ui->label_token_verified->setPixmap(QIcon::fromTheme(QStringLiteral("checked")).pixmap(16));
|
||||
// ui->label_token_verified->setToolTip(tr("Verified", "Tooltip"));
|
||||
// ui->username->setText(
|
||||
// QString::fromStdString(UsernameFromDisplayToken(ui->edit_token->text().toStdString())));
|
||||
// } else {
|
||||
// ui->label_token_verified->setPixmap(QIcon::fromTheme(QStringLiteral("failed")).pixmap(16));
|
||||
// ui->label_token_verified->setToolTip(tr("Verification failed", "Tooltip"));
|
||||
// ui->username->setText(tr("Unspecified"));
|
||||
// QMessageBox::critical(this, tr("Verification failed"),
|
||||
// tr("Verification failed. Check that you have entered your token "
|
||||
// "correctly, and that your internet connection is working."));
|
||||
// }
|
||||
if (username_good) {
|
||||
ui->label_username_verified->setPixmap(checked);
|
||||
ui->label_username_verified->setToolTip(tr("All Good", "Tooltip"));
|
||||
} else {
|
||||
ui->label_username_verified->setPixmap(failed);
|
||||
ui->label_username_verified->setToolTip(tr("Must be between 4-20 characters", "Tooltip"));
|
||||
}
|
||||
|
||||
if (token_good) {
|
||||
ui->label_token_verified->setPixmap(checked);
|
||||
ui->label_token_verified->setToolTip(tr("All Good", "Tooltip"));
|
||||
} else {
|
||||
ui->label_token_verified->setPixmap(failed);
|
||||
ui->label_token_verified->setToolTip(tr("Must be 48 characters, and lowercase a-z", "Tooltip"));
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigureWeb::SetWebServiceConfigEnabled(bool enabled) {
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2017 Citra Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <QFutureWatcher>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
#include <QWidget>
|
||||
#include <memory>
|
||||
|
||||
namespace Ui {
|
||||
class ConfigureWeb;
|
||||
|
@ -25,14 +29,12 @@ private:
|
|||
void changeEvent(QEvent* event) override;
|
||||
void RetranslateUI();
|
||||
|
||||
void OnLoginChanged();
|
||||
void VerifyLogin();
|
||||
void OnLoginVerified();
|
||||
|
||||
void SetConfiguration();
|
||||
|
||||
bool user_verified = true;
|
||||
QFutureWatcher<bool> verify_watcher;
|
||||
|
||||
std::unique_ptr<Ui::ConfigureWeb> ui;
|
||||
QRandomGenerator *m_rng;
|
||||
|
||||
private slots:
|
||||
void GenerateToken();
|
||||
void VerifyLogin();
|
||||
};
|
||||
|
|
|
@ -25,42 +25,29 @@
|
|||
<string>eden Web Service</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayoutYuzuWebService">
|
||||
<item>
|
||||
<widget class="QLabel" name="web_credentials_disclaimer">
|
||||
<property name="text">
|
||||
<string>By providing your username and token, you agree to allow eden to collect additional usage data, which may include user identifying information.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayoutYuzuUsername">
|
||||
<item row="2" column="3">
|
||||
<widget class="QPushButton" name="button_verify_login">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_token">
|
||||
<property name="text">
|
||||
<string>Token: </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_username">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LayoutDirection::RightToLeft</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Verify</string>
|
||||
<string>Username: </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="web_signup_link">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Sign up</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="3">
|
||||
<item row="0" column="1" colspan="4">
|
||||
<widget class="QLineEdit" name="edit_username">
|
||||
<property name="maxLength">
|
||||
<number>20</number>
|
||||
|
@ -70,25 +57,27 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_token">
|
||||
<property name="text">
|
||||
<string>Token: </string>
|
||||
<item row="1" column="5">
|
||||
<widget class="QLabel" name="label_token_verified">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QLabel" name="label_token_verified"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_username">
|
||||
<property name="text">
|
||||
<string>Username: </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="3">
|
||||
<item row="1" column="1" colspan="4">
|
||||
<widget class="QLineEdit" name="edit_token">
|
||||
<property name="inputMethodHints">
|
||||
<set>Qt::InputMethodHint::ImhLowercaseOnly</set>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>80</number>
|
||||
</property>
|
||||
|
@ -97,14 +86,27 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="web_token_info_link">
|
||||
<item row="0" column="5">
|
||||
<widget class="QLabel" name="label_username_verified">
|
||||
<property name="text">
|
||||
<string>What is my token?</string>
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<item row="2" column="4">
|
||||
<widget class="QPushButton" name="button_generate">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Generate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="3">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
|
|
|
@ -602,6 +602,7 @@ std::unique_ptr<ComboboxTranslationMap> ComboboxEnumeration(QWidget* parent)
|
|||
PAIR(Language, ChineseSimplified, tr("Simplified Chinese")),
|
||||
PAIR(Language, ChineseTraditional, tr("Traditional Chinese (正體中文)")),
|
||||
PAIR(Language, PortugueseBrazilian, tr("Brazilian Portuguese (português do Brasil)")),
|
||||
PAIR(Language, Serbian, tr("Serbian (српски)")),
|
||||
}});
|
||||
translations->insert({Settings::EnumMetadata<Settings::Region>::Index(),
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue