Browse Source

Merge pull request #12083 from glassez/app-instances

Allow single app instance per configuration
adaptive-webui-19844
Vladimir Golovnev 5 years ago committed by GitHub
parent
commit
a7b342edcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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 @@ -126,9 +126,8 @@ namespace
#endif
}
Application::Application(const QString &id, int &argc, char **argv)
Application::Application(int &argc, char **argv)
: BaseApplication(argc, argv)
, m_instanceManager(new ApplicationInstanceManager {id, this})
, m_running(false)
, m_shutdownAct(ShutdownDialogAction::Exit)
, m_commandLineArgs(parseCommandLine(this->arguments()))
@ -144,11 +143,16 @@ Application::Application(const QString &id, int &argc, char **argv) @@ -144,11 +143,16 @@ Application::Application(const QString &id, int &argc, char **argv)
QPixmapCache::setCacheLimit(PIXMAP_CACHE_SIZE);
#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
? QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(DEFAULT_PORTABLE_MODE_PROFILE_DIR)
: 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,
(m_commandLineArgs.relativeFastresumePaths || portableModeEnabled));

4
src/app/application.h

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

17
src/app/cmdoptions.h

@ -42,7 +42,11 @@ class QProcessEnvironment; @@ -42,7 +42,11 @@ class QProcessEnvironment;
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)
bool showVersion;
#endif
@ -52,11 +56,16 @@ struct QBtCommandLineParameters @@ -52,11 +56,16 @@ struct QBtCommandLineParameters
bool shouldDaemonize;
#endif
int webUiPort;
TriStateBool addPaused, skipDialog;
TriStateBool addPaused;
TriStateBool skipDialog;
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;
};

7
src/app/main.cpp

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

Loading…
Cancel
Save