From a88d3436cc6b2c24ab05400a5ad5e9e67cb95db8 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Thu, 28 Jan 2021 19:05:05 +0100 Subject: Implementation --pick argument. --- src/commandline.cpp | 8 ++++++++ src/commandline.h | 3 +++ src/main.cpp | 5 ++++- src/moapplication.cpp | 8 ++++---- src/moapplication.h | 4 ++-- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/commandline.cpp b/src/commandline.cpp index 477bfba1..22755dda 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -344,6 +344,9 @@ void CommandLine::createOptions() ("multiple", "allow multiple MO processes to run; see below") + ("pick", + "show the select instance dialog on startup") + ("logs", "duplicates the logs to stdout") @@ -424,6 +427,11 @@ std::string CommandLine::usage(const Command* c) const return oss.str(); } +bool CommandLine::pick() const +{ + return (m_vm.count("pick") > 0); +} + bool CommandLine::multiple() const { return (m_vm.count("multiple") > 0); diff --git a/src/commandline.h b/src/commandline.h index 6bd57132..a0b70fb2 100644 --- a/src/commandline.h +++ b/src/commandline.h @@ -318,6 +318,9 @@ public: // std::string usage(const Command* c=nullptr) const; + // whether --pick was given + // + bool pick() const; // whether --multiple was given // diff --git a/src/main.cpp b/src/main.cpp index 0cd9ba26..60d99817 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,6 +80,8 @@ int run(int argc, char *argv[]) // stuff that's done only once, even if MO restarts in the loop below app.firstTimeSetup(multiProcess); + // force the "Select instance" dialog on startup (only for first loop) + bool pick = cl.pick(); // MO runs in a loop because it can be restarted in several ways, such as // when switching instances or changing some settings @@ -100,7 +102,8 @@ int run(int argc, char *argv[]) // set up plugins, OrganizerCore, etc. { - const auto r = app.setup(multiProcess); + const auto r = app.setup(multiProcess, pick); + pick = false; if (r == RestartExitCode) { // resets things when MO is "restarted" diff --git a/src/moapplication.cpp b/src/moapplication.cpp index 91cac2b1..1289b6ba 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -183,7 +183,7 @@ void MOApplication::firstTimeSetup(MOMultiProcess& multiProcess) Qt::QueuedConnection); } -int MOApplication::setup(MOMultiProcess& multiProcess) +int MOApplication::setup(MOMultiProcess& multiProcess, bool forceSelect) { TimeThis tt("MOApplication setup()"); @@ -192,7 +192,7 @@ int MOApplication::setup(MOMultiProcess& multiProcess) MOBase::details::setPluginDataPath(OrganizerCore::pluginDataPath()); // figuring out the current instance - m_instance = getCurrentInstance(); + m_instance = getCurrentInstance(forceSelect); if (!m_instance) { return 1; } @@ -439,12 +439,12 @@ void MOApplication::externalMessage(const QString& message) } } -std::unique_ptr MOApplication::getCurrentInstance() +std::unique_ptr MOApplication::getCurrentInstance(bool forceSelect) { auto& m = InstanceManager::singleton(); auto currentInstance = m.currentInstance(); - if (!currentInstance) + if (forceSelect || !currentInstance) { // clear any overrides that might have been given on the command line m.clearOverrides(); diff --git a/src/moapplication.h b/src/moapplication.h index 65180ece..d10db320 100644 --- a/src/moapplication.h +++ b/src/moapplication.h @@ -47,7 +47,7 @@ public: // called from main() each time MO "restarts", loads settings, plugins, // OrganizerCore and the current instance // - int setup(MOMultiProcess& multiProcess); + int setup(MOMultiProcess& multiProcess, bool forceSelect); // shows splash, starts an api check, shows the main window and blocks until // MO exits @@ -85,7 +85,7 @@ private: std::unique_ptr m_core; void externalMessage(const QString& message); - std::unique_ptr getCurrentInstance(); + std::unique_ptr getCurrentInstance(bool forceSelect); std::optional setupInstanceLoop(Instance& currentInstance, PluginContainer& pc); void purgeOldFiles(); }; -- cgit v1.3.1