summary refs log tree commit diff
path: root/src/main.cpp
diff options
context:
space:
mode:
authortrilene <trilene@runbox.com>2020-10-27 15:29:53 -0400
committertrilene <trilene@runbox.com>2020-10-27 15:29:53 -0400
commitd9ca5309ac0e5f25e0af6cc75a9b31e79a33d4d7 (patch)
treeecf31e7dde13cae5c4c24b256542b77dd31f6d79 /src/main.cpp
parentSupport video calls (diff)
parentTranslated using Weblate (English) (diff)
downloadnheko-d9ca5309ac0e5f25e0af6cc75a9b31e79a33d4d7.tar.xz
Merge remote-tracking branch 'upstream/master' into webrtc-video
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp

index e02ffa36..6fbccf5c 100644 --- a/src/main.cpp +++ b/src/main.cpp
@@ -104,10 +104,32 @@ createCacheDirectory() int main(int argc, char *argv[]) { - // needed for settings so need to register before any settings are read to prevent warings + // needed for settings so need to register before any settings are read to prevent warnings qRegisterMetaType<UserSettings::Presence>(); - QCoreApplication::setApplicationName("nheko"); + // This is some hacky programming, but it's necessary (AFAIK?) to get the unique config name + // parsed before the app name is set. + QString appName{"nheko"}; + for (int i = 0; i < argc; ++i) { + if (QString{argv[i]}.startsWith("--profile=")) { + QString q{argv[i]}; + q.remove("--profile="); + appName += "-" + q; + } else if (QString{argv[i]}.startsWith("--p=")) { + QString q{argv[i]}; + q.remove("-p="); + appName += "-" + q; + } else if (QString{argv[i]} == "--profile" || QString{argv[i]} == "-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 + appName += "-" + QString{argv[i]}; + } + } + } + + QCoreApplication::setApplicationName(appName); QCoreApplication::setApplicationVersion(nheko::version); QCoreApplication::setOrganizationName("nheko"); QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); @@ -137,6 +159,19 @@ main(int argc, char *argv[]) parser.addVersionOption(); QCommandLineOption debugOption("debug", "Enable debug output"); parser.addOption(debugOption); + + // This option is not actually parsed via Qt due to the need to parse it before the app + // name is set. It only exists to keep Qt from complaining about the --profile/-p + // option and thereby crashing the app. + QCommandLineOption configName( + QStringList() << "p" + << "profile", + QCoreApplication::tr("Create a unique profile, which allows you to log into several " + "accounts at the same time and start multiple instances of nheko."), + QCoreApplication::tr("profile"), + QCoreApplication::tr("profile name")); + parser.addOption(configName); + parser.process(app); app.setWindowIcon(QIcon(":/logos/nheko.png")); @@ -181,7 +216,7 @@ main(int argc, char *argv[]) appTranslator.load(QLocale(), "nheko", "_", ":/translations"); app.installTranslator(&appTranslator); - MainWindow w; + MainWindow w{(appName == "nheko" ? "" : appName.remove("nheko-"))}; // Move the MainWindow to the center w.move(screenCenter(w.width(), w.height()));