From 85b5b816cfa28371d9c78097eab22d6ec7438eee Mon Sep 17 00:00:00 2001
From: Kewlan <colin_rehn@hotmail.com>
Date: Wed, 21 Oct 2020 20:36:57 +0200
Subject: [PATCH] Don't ask for profile when there's only one.

---
 src/yuzu/applets/profile_select.cpp |  9 +++++++++
 src/yuzu/applets/profile_select.h   |  1 +
 src/yuzu/main.cpp                   | 26 ++++++++++----------------
 3 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/src/yuzu/applets/profile_select.cpp b/src/yuzu/applets/profile_select.cpp
index dca8835edb..68b76269d0 100644
--- a/src/yuzu/applets/profile_select.cpp
+++ b/src/yuzu/applets/profile_select.cpp
@@ -114,6 +114,15 @@ QtProfileSelectionDialog::QtProfileSelectionDialog(QWidget* parent)
 
 QtProfileSelectionDialog::~QtProfileSelectionDialog() = default;
 
+int QtProfileSelectionDialog::exec() {
+    // Skip profile selection when there's only one.
+    if (profile_manager->GetUserCount() == 1) {
+        user_index = 0;
+        return QDialog::Accepted;
+    }
+    QDialog::exec();
+}
+
 void QtProfileSelectionDialog::accept() {
     QDialog::accept();
 }
diff --git a/src/yuzu/applets/profile_select.h b/src/yuzu/applets/profile_select.h
index cee886a778..29c33cca0c 100644
--- a/src/yuzu/applets/profile_select.h
+++ b/src/yuzu/applets/profile_select.h
@@ -27,6 +27,7 @@ public:
     explicit QtProfileSelectionDialog(QWidget* parent);
     ~QtProfileSelectionDialog() override;
 
+    int exec() override;
     void accept() override;
     void reject() override;
 
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index e3de0f0e1d..18e68e5907 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -303,24 +303,18 @@ void GMainWindow::ControllerSelectorReconfigureControllers(
 }
 
 void GMainWindow::ProfileSelectorSelectProfile() {
-    const Service::Account::ProfileManager manager;
-    int index = 0;
-    if (manager.GetUserCount() != 1) {
-        QtProfileSelectionDialog dialog(this);
-        dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint |
-                              Qt::WindowTitleHint | Qt::WindowSystemMenuHint |
-                              Qt::WindowCloseButtonHint);
-        dialog.setWindowModality(Qt::WindowModal);
-
-        if (dialog.exec() == QDialog::Rejected) {
-            emit ProfileSelectorFinishedSelection(std::nullopt);
-            return;
-        }
-
-        index = dialog.GetIndex();
+    QtProfileSelectionDialog dialog(this);
+    dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint |
+                          Qt::WindowTitleHint | Qt::WindowSystemMenuHint |
+                          Qt::WindowCloseButtonHint);
+    dialog.setWindowModality(Qt::WindowModal);
+    if (dialog.exec() == QDialog::Rejected) {
+        emit ProfileSelectorFinishedSelection(std::nullopt);
+        return;
     }
 
-    const auto uuid = manager.GetUser(static_cast<std::size_t>(index));
+    const Service::Account::ProfileManager manager;
+    const auto uuid = manager.GetUser(static_cast<std::size_t>(dialog.GetIndex()));
     if (!uuid.has_value()) {
         emit ProfileSelectorFinishedSelection(std::nullopt);
         return;