Browse Source

Revise classes startup sequence

1. Initialize Logger class earlier so that it can record messages from other classes (for
   debugging purpose).
2. Deprioritize WebUI port adjustment. It is not a high priority in here.
3. Slightly deprioritize file logger initialization.
adaptive-webui-19844
Chocobo1 2 years ago
parent
commit
ec13bba4da
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 23
      src/app/application.cpp

23
src/app/application.cpp

@ -147,6 +147,8 @@ Application::Application(int &argc, char **argv)
QPixmapCache::setCacheLimit(PIXMAP_CACHE_SIZE); QPixmapCache::setCacheLimit(PIXMAP_CACHE_SIZE);
#endif #endif
Logger::initInstance();
const auto portableProfilePath = Path(QCoreApplication::applicationDirPath()) / DEFAULT_PORTABLE_MODE_PROFILE_DIR; const auto portableProfilePath = Path(QCoreApplication::applicationDirPath()) / DEFAULT_PORTABLE_MODE_PROFILE_DIR;
const bool portableModeEnabled = m_commandLineArgs.profileDir.isEmpty() && portableProfilePath.exists(); const bool portableModeEnabled = m_commandLineArgs.profileDir.isEmpty() && portableProfilePath.exists();
@ -158,35 +160,34 @@ Application::Application(int &argc, char **argv)
m_instanceManager = new ApplicationInstanceManager(Profile::instance()->location(SpecialFolder::Config), this); m_instanceManager = new ApplicationInstanceManager(Profile::instance()->location(SpecialFolder::Config), this);
Logger::initInstance();
SettingsStorage::initInstance(); SettingsStorage::initInstance();
Preferences::initInstance(); Preferences::initInstance();
initializeTranslation(); initializeTranslation();
if (m_commandLineArgs.webUiPort > 0) // it will be -1 when user did not set any value
Preferences::instance()->setWebUiPort(m_commandLineArgs.webUiPort);
connect(this, &QCoreApplication::aboutToQuit, this, &Application::cleanup); connect(this, &QCoreApplication::aboutToQuit, this, &Application::cleanup);
connect(m_instanceManager, &ApplicationInstanceManager::messageReceived, this, &Application::processMessage); connect(m_instanceManager, &ApplicationInstanceManager::messageReceived, this, &Application::processMessage);
#if defined(Q_OS_WIN) && !defined(DISABLE_GUI) #if defined(Q_OS_WIN) && !defined(DISABLE_GUI)
connect(this, &QGuiApplication::commitDataRequest, this, &Application::shutdownCleanup, Qt::DirectConnection); connect(this, &QGuiApplication::commitDataRequest, this, &Application::shutdownCleanup, Qt::DirectConnection);
#endif #endif
if (isFileLoggerEnabled()) LogMsg(tr("qBittorrent %1 started", "qBittorrent v3.2.0alpha started").arg(QStringLiteral(QBT_VERSION)));
m_fileLogger = new FileLogger(fileLoggerPath(), isFileLoggerBackup(), fileLoggerMaxSize(), isFileLoggerDeleteOld(), fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(fileLoggerAgeType()));
Logger::instance()->addMessage(tr("qBittorrent %1 started", "qBittorrent v3.2.0alpha started").arg(QStringLiteral(QBT_VERSION)));
if (portableModeEnabled) if (portableModeEnabled)
{ {
Logger::instance()->addMessage(tr("Running in portable mode. Auto detected profile folder at: %1").arg(profileDir.toString())); LogMsg(tr("Running in portable mode. Auto detected profile folder at: %1").arg(profileDir.toString()));
if (m_commandLineArgs.relativeFastresumePaths) if (m_commandLineArgs.relativeFastresumePaths)
Logger::instance()->addMessage(tr("Redundant command line flag detected: \"%1\". Portable mode implies relative fastresume.").arg(u"--relative-fastresume"_qs), Log::WARNING); // to avoid translating the `--relative-fastresume` string LogMsg(tr("Redundant command line flag detected: \"%1\". Portable mode implies relative fastresume.").arg(u"--relative-fastresume"_qs), Log::WARNING); // to avoid translating the `--relative-fastresume` string
} }
else else
{ {
Logger::instance()->addMessage(tr("Using config directory: %1").arg(Profile::instance()->location(SpecialFolder::Config).toString())); LogMsg(tr("Using config directory: %1").arg(Profile::instance()->location(SpecialFolder::Config).toString()));
} }
if (isFileLoggerEnabled())
m_fileLogger = new FileLogger(fileLoggerPath(), isFileLoggerBackup(), fileLoggerMaxSize(), isFileLoggerDeleteOld(), fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(fileLoggerAgeType()));
if (m_commandLineArgs.webUiPort > 0) // it will be -1 when user did not set any value
Preferences::instance()->setWebUiPort(m_commandLineArgs.webUiPort);
} }
Application::~Application() Application::~Application()

Loading…
Cancel
Save