mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-24 03:58:49 +03:00
Fix an empty profile name allowing you to open a profile twice
This commit is contained in:
parent
d3561d7939
commit
3ad0f15f6d
1 changed files with 14 additions and 28 deletions
42
src/main.cpp
42
src/main.cpp
|
@ -178,36 +178,16 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
QString matrixUri;
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
QString arg{argv[i]};
|
QString arg{argv[i]};
|
||||||
if (arg.startsWith(QLatin1String("--profile="))) {
|
if (arg.startsWith(QLatin1String("matrix:"))) {
|
||||||
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:"))) {
|
|
||||||
matrixUri = arg;
|
matrixUri = arg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
KDSingleApplication singleapp(
|
|
||||||
QStringLiteral("im.nheko.nheko-%1")
|
|
||||||
.arg(userdata == QLatin1String("default") ? QLatin1String("") : userdata));
|
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
parser.addVersionOption();
|
parser.addVersionOption();
|
||||||
|
@ -250,6 +230,19 @@ main(int argc, char *argv[])
|
||||||
if (parser.isSet(compactDb))
|
if (parser.isSet(compactDb))
|
||||||
cache::setNeedsCompactFlag();
|
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
|
// This check needs to happen _after_ process(), so that we actually print help for --help when
|
||||||
// Nheko is already running.
|
// Nheko is already running.
|
||||||
if (!singleapp.isPrimaryInstance()) {
|
if (!singleapp.isPrimaryInstance()) {
|
||||||
|
@ -370,13 +363,6 @@ main(int argc, char *argv[])
|
||||||
auto filter = new NhekoFixupPaletteEventFilter(&app);
|
auto filter = new NhekoFixupPaletteEventFilter(&app);
|
||||||
app.installEventFilter(filter);
|
app.installEventFilter(filter);
|
||||||
|
|
||||||
if (parser.isSet(configName))
|
|
||||||
UserSettings::initialize(parser.value(configName));
|
|
||||||
else
|
|
||||||
UserSettings::initialize(std::nullopt);
|
|
||||||
|
|
||||||
auto settings = UserSettings::instance().toWeakRef();
|
|
||||||
|
|
||||||
QFont font;
|
QFont font;
|
||||||
QString userFontFamily = settings.lock()->font();
|
QString userFontFamily = settings.lock()->font();
|
||||||
if (!userFontFamily.isEmpty() && userFontFamily != QLatin1String("default")) {
|
if (!userFontFamily.isEmpty() && userFontFamily != QLatin1String("default")) {
|
||||||
|
|
Loading…
Reference in a new issue