Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command line argoment to allow more than single instance of app running #112

Open
Mart-Bogdan opened this issue Jan 13, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@Mart-Bogdan
Copy link

I've noticed in Readme that SingleApplication is required dependency.

And I confirmed it in code of Main and by program behavior, that I can't launch more then one instance of app.

I don't see why. I've used to similar apps on windows that don't have this constraint.

You just launch any instances you like.

So it is useful to bench two different drives in one go, and visually compare them/make screenshot of two windows.

@Mart-Bogdan Mart-Bogdan added bug Something isn't working unconfirmed labels Jan 13, 2023
@Mart-Bogdan
Copy link
Author

P.S. IDK why it has bug label, but I wasn't able to change labels upon issue creation.

@Mart-Bogdan
Copy link
Author

Would it be ok for me to create PR with something along this lines:

diff --git a/src/main.cpp b/src/main.cpp
index e300159..422d6c8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,6 +5,8 @@
 #include "singleapplication.h"
 #include "cmake.h"
 
+bool use_multi_instance(int argc, char *argv[]);
+
 int main(int argc, char *argv[])
 {
     QCoreApplication::setApplicationName(QStringLiteral(PROJECT_NAME));
@@ -13,7 +15,12 @@ int main(int argc, char *argv[])
 
     QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
 
-    SingleApplication a(argc, argv);
+    std::unique_ptr<QApplication> a;
+    if (use_multi_instance(argc, argv)) {
+        a = std::make_unique<QApplication>(argc, argv);
+    } else {
+        a = std::make_unique<SingleApplication>(argc, argv);
+    }
 
     AppSettings().setupLocalization();
 
@@ -21,5 +28,17 @@ int main(int argc, char *argv[])
     w.setFixedSize(w.size());
     w.show();
 
-    return a.exec();
+    return a->exec();
 }
+
+const std::string MULTI_INSTANCE_ARG = "--multi-instance";
+
+bool use_multi_instance(int argc, char *argv[])
+{
+    for (int i = 0; i < argc; ++i) {
+        if (argv[i] == MULTI_INSTANCE_ARG) {
+            return true;
+        }
+    }
+    return false;
+}
\ No newline at end of file

Command swith to be decided. And sorry for code stype. I've have to look at style used across the project etc.

But that's just a a sketch.

As I understand: before we created QApplication instance we can't use Qt's facility to parse arguments, so have to do it manually.

@Mart-Bogdan
Copy link
Author

Turns out this solution is better:

diff --git a/src/main.cpp b/src/main.cpp
index e300159..872bb6d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,6 +5,8 @@
 #include "singleapplication.h"
 #include "cmake.h"
 
+bool use_multi_instance(int argc, char *argv[]);
+
 int main(int argc, char *argv[])
 {
     QCoreApplication::setApplicationName(QStringLiteral(PROJECT_NAME));
@@ -13,7 +15,7 @@ int main(int argc, char *argv[])
 
     QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
 
-    SingleApplication a(argc, argv);
+    SingleApplication a(argc, argv, use_multi_instance(argc, argv));
 
     AppSettings().setupLocalization();
 
@@ -23,3 +25,15 @@ int main(int argc, char *argv[])
 
     return a.exec();
 }
+
+const std::string MULTI_INSTANCE_ARG = "--multi-instance";
+
+bool use_multi_instance(int argc, char *argv[])
+{
+    for (int i = 0; i < argc; ++i) {
+        if (argv[i] == MULTI_INSTANCE_ARG) {
+            return true;
+        }
+    }
+    return false;
+}
\ No newline at end of file

@Mart-Bogdan
Copy link
Author

I jsut got thought. Would this create problems with helper?

@JonMagon JonMagon added enhancement New feature or request and removed bug Something isn't working unconfirmed labels Feb 23, 2023
@JonMagon
Copy link
Owner

I jsut got thought. Would this create problems with helper?

This can cause problems when running simultaneous tests. But the flag idea is a good one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants