Exemplo n.º 1
0
ApplicationLauncher::ApplicationLauncher(QObject *parent) :
    application::LauncherBase(parent),
    m_launcherObject(nullptr),
    m_synced(false),
    m_temporaryDir(nullptr)
{
    initializeObject();
    createTemporaryDir();
    addLauncherTopic("launcher");
}
Exemplo n.º 2
0
QString handleNewAppInstance(QtSingleApplication *singleApp, int argc, char **argv, const QString &newInstanceArg)
{
  if (singleApp->isRunning())
  {
    QStringList args;
    bool newInstance = false;
    for (int i = 1; i < argc; ++i)
    {
      args << argv[i];
      if (args.back().endsWith(newInstanceArg))
      {
        newInstance = true;
      }
    }

    if (newInstance)
    {
      QString path;
      if (!createTemporaryDir(path))
      {
        qCritical("Could not create temporary storage path for new application instance.");
        exit(EXIT_FAILURE);
      }
      qWarning("Forcing new application instance. The application data will be written to a temporary directory.");
      return path;
    }
    else
    {
      QByteArray ba;
      QDataStream msg(&ba, QIODevice::WriteOnly);
      msg << QString("$cmdLineArgs"); // This message contains command line arguments
      msg << args;
      if (singleApp->sendMessage(ba))
      {
        exit(EXIT_SUCCESS);
      }
      else
      {
        qCritical("The running application seems to be frozen.");
        exit(EXIT_FAILURE);
      }
    }
  }
  return QString();
}