From 6122b5421096ee5cf6bfcda5273f27a1f0b8095c Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 19 Oct 2020 19:03:42 +0200 Subject: [PATCH] Add an opt-out for the single-process behavior This would have been useful for testing multiple times and now even came up in a forum discussion. --- tray/application/main.cpp | 4 +++- tray/application/singleinstance.cpp | 6 +++++- tray/application/singleinstance.h | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tray/application/main.cpp b/tray/application/main.cpp index 9f0ef54..1c39430 100644 --- a/tray/application/main.cpp +++ b/tray/application/main.cpp @@ -159,6 +159,7 @@ int runApplication(int argc, const char *const *argv) connectionArg.setRequiredValueCount(Argument::varValueCount); ConfigValueArgument configPathArg("config-dir-path", '\0', "specifies the path to the configuration directory", { "path" }); configPathArg.setEnvironmentVariable(PROJECT_VARNAME_UPPER "_CONFIG_DIR"); + ConfigValueArgument newInstanceArg("new-instance", '\0', "disable the usual single-process behavior"); Argument &widgetsGuiArg = qtConfigArgs.qtWidgetsGuiArg(); widgetsGuiArg.addSubArgument(&windowedArg); widgetsGuiArg.addSubArgument(&showWebUiArg); @@ -166,6 +167,7 @@ int runApplication(int argc, const char *const *argv) widgetsGuiArg.addSubArgument(&waitForTrayArg); widgetsGuiArg.addSubArgument(&connectionArg); widgetsGuiArg.addSubArgument(&configPathArg); + widgetsGuiArg.addSubArgument(&newInstanceArg); parser.setMainArguments({ &qtConfigArgs.qtWidgetsGuiArg(), &parser.noColorArg(), &parser.helpArg() }); parser.parseArgs(argc, argv); @@ -187,7 +189,7 @@ int runApplication(int argc, const char *const *argv) SET_QT_APPLICATION_INFO; QApplication application(argc, const_cast(argv)); QGuiApplication::setQuitOnLastWindowClosed(false); - SingleInstance singleInstance(argc, argv); + SingleInstance singleInstance(argc, argv, newInstanceArg.isPresent()); networkAccessManager().setParent(&singleInstance); QObject::connect(&singleInstance, &SingleInstance::newInstance, &runApplication); Settings::restore(); diff --git a/tray/application/singleinstance.cpp b/tray/application/singleinstance.cpp index 56038fc..9909442 100644 --- a/tray/application/singleinstance.cpp +++ b/tray/application/singleinstance.cpp @@ -17,10 +17,14 @@ using namespace CppUtilities::EscapeCodes; namespace QtGui { -SingleInstance::SingleInstance(int argc, const char *const *argv, QObject *parent) +SingleInstance::SingleInstance(int argc, const char *const *argv, bool newInstance, QObject *parent) : QObject(parent) , m_server(nullptr) { + if (newInstance) { + return; + } + const QString appId(QCoreApplication::applicationName() % QStringLiteral(" by ") % QCoreApplication::organizationName()); // check for previous instance diff --git a/tray/application/singleinstance.h b/tray/application/singleinstance.h index 97d5cc4..d774c7c 100644 --- a/tray/application/singleinstance.h +++ b/tray/application/singleinstance.h @@ -14,7 +14,7 @@ namespace QtGui { class SingleInstance : public QObject { Q_OBJECT public: - SingleInstance(int argc, const char *const *argv, QObject *parent = nullptr); + SingleInstance(int argc, const char *const *argv, bool newInstance = false, QObject *parent = nullptr); Q_SIGNALS: void newInstance(int argc, const char *const *argv);