mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-22 20:44:15 +00:00
Merge pull request #12083 from glassez/app-instances
Allow single app instance per configuration
This commit is contained in:
commit
a7b342edcb
@ -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));
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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"
|
||||||
@ -141,11 +140,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.")
|
||||||
@ -264,7 +261,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…
x
Reference in New Issue
Block a user