Browse Source

Allow single app instance per configuration

adaptive-webui-19844
Vladimir Golovnev (Glassez) 5 years ago
parent
commit
38e54206d5
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 10
      src/app/application.cpp
  2. 4
      src/app/application.h
  3. 17
      src/app/cmdoptions.h
  4. 7
      src/app/main.cpp

10
src/app/application.cpp

@ -126,9 +126,8 @@ namespace
#endif #endif
} }
Application::Application(const QString &id, int &argc, char **argv) Application::Application(int &argc, char **argv)
: BaseApplication(argc, argv) : BaseApplication(argc, argv)
, m_instanceManager(new ApplicationInstanceManager {id, this})
, m_running(false) , m_running(false)
, m_shutdownAct(ShutdownDialogAction::Exit) , m_shutdownAct(ShutdownDialogAction::Exit)
, m_commandLineArgs(parseCommandLine(this->arguments())) , m_commandLineArgs(parseCommandLine(this->arguments()))
@ -144,11 +143,16 @@ Application::Application(const QString &id, int &argc, char **argv)
QPixmapCache::setCacheLimit(PIXMAP_CACHE_SIZE); QPixmapCache::setCacheLimit(PIXMAP_CACHE_SIZE);
#endif #endif
const bool portableModeEnabled = m_commandLineArgs.profileDir.isEmpty() && QDir(QCoreApplication::applicationDirPath()).exists(DEFAULT_PORTABLE_MODE_PROFILE_DIR); const bool portableModeEnabled = m_commandLineArgs.profileDir.isEmpty()
&& QDir(QCoreApplication::applicationDirPath()).exists(DEFAULT_PORTABLE_MODE_PROFILE_DIR);
const QString profileDir = portableModeEnabled const QString profileDir = portableModeEnabled
? QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(DEFAULT_PORTABLE_MODE_PROFILE_DIR) ? QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(DEFAULT_PORTABLE_MODE_PROFILE_DIR)
: m_commandLineArgs.profileDir; : m_commandLineArgs.profileDir;
const QString appId = QLatin1String("qBittorrent-") + Utils::Misc::getUserIDString() + '@' + profileDir
+ (m_commandLineArgs.configurationName.isEmpty() ? QString {} : ('/' + m_commandLineArgs.configurationName));
m_instanceManager = new ApplicationInstanceManager {appId, this};
Profile::initInstance(profileDir, m_commandLineArgs.configurationName, Profile::initInstance(profileDir, m_commandLineArgs.configurationName,
(m_commandLineArgs.relativeFastresumePaths || portableModeEnabled)); (m_commandLineArgs.relativeFastresumePaths || portableModeEnabled));

4
src/app/application.h

@ -74,7 +74,7 @@ class Application : public BaseApplication
Q_DISABLE_COPY(Application) Q_DISABLE_COPY(Application)
public: public:
Application(const QString &id, int &argc, char **argv); Application(int &argc, char **argv);
~Application() override; ~Application() override;
bool isRunning(); bool isRunning();
@ -120,7 +120,7 @@ private slots:
#endif #endif
private: private:
ApplicationInstanceManager *m_instanceManager; ApplicationInstanceManager *m_instanceManager = nullptr;
bool m_running; bool m_running;
ShutdownDialogAction m_shutdownAct; ShutdownDialogAction m_shutdownAct;
QBtCommandLineParameters m_commandLineArgs; QBtCommandLineParameters m_commandLineArgs;

17
src/app/cmdoptions.h

@ -42,7 +42,11 @@ class QProcessEnvironment;
struct QBtCommandLineParameters struct QBtCommandLineParameters
{ {
bool showHelp, relativeFastresumePaths, skipChecking, sequential, firstLastPiecePriority; bool showHelp;
bool relativeFastresumePaths;
bool skipChecking;
bool sequential;
bool firstLastPiecePriority;
#if !defined(Q_OS_WIN) || defined(DISABLE_GUI) #if !defined(Q_OS_WIN) || defined(DISABLE_GUI)
bool showVersion; bool showVersion;
#endif #endif
@ -52,11 +56,16 @@ struct QBtCommandLineParameters
bool shouldDaemonize; bool shouldDaemonize;
#endif #endif
int webUiPort; int webUiPort;
TriStateBool addPaused, skipDialog; TriStateBool addPaused;
TriStateBool skipDialog;
QStringList torrents; QStringList torrents;
QString profileDir, configurationName, savePath, category, unknownParameter; QString profileDir;
QString configurationName;
QString savePath;
QString category;
QString unknownParameter;
explicit QBtCommandLineParameters(const QProcessEnvironment&); explicit QBtCommandLineParameters(const QProcessEnvironment &);
QStringList paramList() const; QStringList paramList() const;
}; };

7
src/app/main.cpp

@ -78,7 +78,6 @@ Q_IMPORT_PLUGIN(QICOPlugin)
#include "base/preferences.h" #include "base/preferences.h"
#include "base/profile.h" #include "base/profile.h"
#include "base/utils/misc.h"
#include "application.h" #include "application.h"
#include "cmdoptions.h" #include "cmdoptions.h"
#include "upgrade.h" #include "upgrade.h"
@ -135,11 +134,9 @@ int main(int argc, char *argv[])
try { try {
// Create Application // Create Application
const QString appId = QLatin1String("qBittorrent-") + Utils::Misc::getUserIDString(); auto app = std::make_unique<Application>(argc, argv);
auto app = std::make_unique<Application>(appId, argc, argv);
const QBtCommandLineParameters params = app->commandLineArgs(); const QBtCommandLineParameters params = app->commandLineArgs();
if (!params.unknownParameter.isEmpty()) { if (!params.unknownParameter.isEmpty()) {
throw CommandLineParameterError(QObject::tr("%1 is an unknown command line parameter.", throw CommandLineParameterError(QObject::tr("%1 is an unknown command line parameter.",
"--random-parameter is an unknown command line parameter.") "--random-parameter is an unknown command line parameter.")
@ -258,7 +255,7 @@ int main(int argc, char *argv[])
if (params.shouldDaemonize) { if (params.shouldDaemonize) {
app.reset(); // Destroy current application app.reset(); // Destroy current application
if (daemon(1, 0) == 0) { if (daemon(1, 0) == 0) {
app = std::make_unique<Application>(appId, argc, argv); app = std::make_unique<Application>(argc, argv);
if (app->isRunning()) { if (app->isRunning()) {
// Another instance had time to start. // Another instance had time to start.
return EXIT_FAILURE; return EXIT_FAILURE;

Loading…
Cancel
Save