Repository: xbmc/xbmc
File: xbmc/application/Application.cpp (C++)

Code before:

  const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();

  profileManager->GetEventLog().Add(EventPtr(new CNotificationEvent(
      StringUtils::Format(g_localizeStrings.Get(177), g_sysinfo.GetAppName()),
      StringUtils::Format(g_localizeStrings.Get(178), g_sysinfo.GetAppName()),
      "special://xbmc/media/icon256x256.png", EventLevel::Basic)));

  m_ServiceManager->GetNetwork().WaitForNet();

  // initialize (and update as needed) our databases
  CDatabaseManager &databaseManager = m_ServiceManager->GetDatabaseManager();

  CEvent event(true);
  CServiceBroker::GetJobManager()->Submit([&databaseManager, &event]() {
    databaseManager.Initialize();
    event.Set();
  });

  std::string localizedStr = g_localizeStrings.Get(24150);
  int iDots = 1;
  while (!event.Wait(1000ms))
  {
    if (databaseManager.IsUpgrading())
      CServiceBroker::GetRenderSystem()->ShowSplash(std::string(iDots, ' ') + localizedStr + std::string(iDots, '.'));

    if (iDots == 3)
      iDots = 1;
    else
      ++iDots;
  }
  CServiceBroker::GetRenderSystem()->ShowSplash("");

  // Initialize GUI font manager to build/update fonts cache
  //! @todo Move GUIFontManager into service broker and drop the global reference
  event.Reset();
  GUIFontManager& guiFontManager = g_fontManager;
  CServiceBroker::GetJobManager()->Submit([&guiFontManager, &event]() {
    guiFontManager.Initialize();
    event.Set();
  });
  localizedStr = g_localizeStrings.Get(39175);
  iDots = 1;
  while (!event.Wait(1000ms))
  {
    if (g_fontManager.IsUpdating())
      CServiceBroker::GetRenderSystem()->ShowSplash(std::string(iDots, ' ') + localizedStr +
                                                    std::string(iDots, '.'));

    if (iDots == 3)
      iDots = 1;

Review comment (performance):
@ksooo can this be read like
 "if the submitted event takes longer than 1000ms then display the text message on the splash"?

i'm asking because i'm testing LE13 on a slow raspberry pi and i _always_ see the message "Database migration in progress... please wait" ..... even though there is no database migration executed.
nothing in the loig about a database migration, and my shared mariadb is already migrated.

in that case the amount of time should be increased a little, maybe 2500ms?

on my living room htpc - which is way faster - i do not get the message on the splash.


Code after:

  const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();

  profileManager->GetEventLog().Add(EventPtr(new CNotificationEvent(
      StringUtils::Format(g_localizeStrings.Get(177), g_sysinfo.GetAppName()),
      StringUtils::Format(g_localizeStrings.Get(178), g_sysinfo.GetAppName()),
      "special://xbmc/media/icon256x256.png", EventLevel::Basic)));

  m_ServiceManager->GetNetwork().WaitForNet();

  // initialize (and update as needed) our databases
  CDatabaseManager &databaseManager = m_ServiceManager->GetDatabaseManager();

  bool allDatabasesInitialized{false};
  CEvent event(true);
  CServiceBroker::GetJobManager()->Submit(
      [&allDatabasesInitialized, &databaseManager, &event]()
      {
        allDatabasesInitialized = databaseManager.Initialize();
        event.Set();
      });

  const std::string connecting{g_localizeStrings.Get(24186)};
  const std::string updating{g_localizeStrings.Get(24150)};
  int iDots = 1;
  while (!event.Wait(1000ms))
  {
    CServiceBroker::GetRenderSystem()->ShowSplash(
        std::string(iDots, ' ') + (databaseManager.IsConnecting() ? connecting : updating) +
        std::string(iDots, '.'));

    if (iDots == 3)
      iDots = 1;
    else
      ++iDots;
  }
  CServiceBroker::GetRenderSystem()->ShowSplash("");

  if (!allDatabasesInitialized)
  {
    // Bail out if any of the databases failed to initialize properly.
    CLog::Log(LOGFATAL, "Failed to initialize databases");

    const std::string dbInitFailedExiting{g_localizeStrings.Get(24187)};

    unsigned int secondsLeftUntilExit{10};
    while (secondsLeftUntilExit)
    {
      CServiceBroker::GetRenderSystem()->ShowSplash(
          StringUtils::Format(dbInitFailedExiting, secondsLeftUntilExit));
      KODI::TIME::Sleep(1s);