summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2024-05-27 21:15:44 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2024-05-27 21:15:44 +0200
commit3ad0f15f6de21024a139e08ad7c62cc7160d4fb2 (patch)
treec3b68dac00458391bb8be43e9de2884f76ef2a4c /src
parentMerge pull request #1727 from checkraisefold/test_linux_fix (diff)
downloadnheko-3ad0f15f6de21024a139e08ad7c62cc7160d4fb2.tar.xz
Fix an empty profile name allowing you to open a profile twice
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp42
1 files changed, 14 insertions, 28 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 15519b8a..8ea15901 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -178,36 +178,16 @@ main(int argc, char *argv[])
     }
 #endif
 
-    // This is some hacky programming, but it's necessary (AFAIK?) to get the unique config name
-    // parsed before the SingleApplication userdata is set.
-    QString userdata{QLatin1String("")};
     QString matrixUri;
     for (int i = 1; i < argc; ++i) {
         QString arg{argv[i]};
-        if (arg.startsWith(QLatin1String("--profile="))) {
-            arg.remove(QStringLiteral("--profile="));
-            userdata = arg;
-        } else if (arg.startsWith(QLatin1String("-p="))) {
-            arg.remove(QStringLiteral("-p="));
-            userdata = arg;
-        } else if (arg == QLatin1String("--profile") || arg == QLatin1String("-p")) {
-            if (i < argc - 1) // if i is less than argc - 1, we still have a parameter
-                              // left to process as the name
-            {
-                ++i; // the next arg is the name, so increment
-                userdata = QString{argv[i]};
-            }
-        } else if (arg.startsWith(QLatin1String("matrix:"))) {
+        if (arg.startsWith(QLatin1String("matrix:"))) {
             matrixUri = arg;
         }
     }
 
     QApplication app(argc, argv);
 
-    KDSingleApplication singleapp(
-      QStringLiteral("im.nheko.nheko-%1")
-        .arg(userdata == QLatin1String("default") ? QLatin1String("") : userdata));
-
     QCommandLineParser parser;
     parser.addHelpOption();
     parser.addVersionOption();
@@ -250,6 +230,19 @@ main(int argc, char *argv[])
     if (parser.isSet(compactDb))
         cache::setNeedsCompactFlag();
 
+    if (parser.isSet(configName))
+        UserSettings::initialize(parser.value(configName));
+    else
+        UserSettings::initialize(std::nullopt);
+
+    auto settings = UserSettings::instance().toWeakRef();
+
+    auto profileName = settings.lock()->profile();
+
+    KDSingleApplication singleapp(
+      QStringLiteral("im.nheko.nheko-%1")
+        .arg(profileName == QLatin1String("default") ? QLatin1String("") : profileName));
+
     // This check needs to happen _after_ process(), so that we actually print help for --help when
     // Nheko is already running.
     if (!singleapp.isPrimaryInstance()) {
@@ -370,13 +363,6 @@ main(int argc, char *argv[])
     auto filter = new NhekoFixupPaletteEventFilter(&app);
     app.installEventFilter(filter);
 
-    if (parser.isSet(configName))
-        UserSettings::initialize(parser.value(configName));
-    else
-        UserSettings::initialize(std::nullopt);
-
-    auto settings = UserSettings::instance().toWeakRef();
-
     QFont font;
     QString userFontFamily = settings.lock()->font();
     if (!userFontFamily.isEmpty() && userFontFamily != QLatin1String("default")) {