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
|
||||
}
|
||||
|
||||
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)
|
||||
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));
|
||||
|
||||
|
@ -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:
|
||||
#endif
|
||||
|
||||
private:
|
||||
ApplicationInstanceManager *m_instanceManager;
|
||||
ApplicationInstanceManager *m_instanceManager = nullptr;
|
||||
bool m_running;
|
||||
ShutdownDialogAction m_shutdownAct;
|
||||
QBtCommandLineParameters m_commandLineArgs;
|
||||
|
@ -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
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -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[])
|
||||
|
||||
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[])
|
||||
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…
x
Reference in New Issue
Block a user