mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-23 05:45:35 +08:00
refs #883, application class extended
* allow to register application as running (needed for launcher) * getExecutableForApplication * swift launcher can be started
This commit is contained in:
committed by
Mathew Sutcliffe
parent
c8c18b0b21
commit
24a9b332b0
@@ -43,6 +43,7 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
|
#include <QProcess>
|
||||||
#include <QSslSocket>
|
#include <QSslSocket>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
@@ -149,15 +150,20 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CApplication::registerAsRunning()
|
||||||
|
{
|
||||||
|
CApplicationInfoList apps = getRunningApplications();
|
||||||
|
const CApplicationInfo myself = instance()->getApplicationInfo();
|
||||||
|
if (!apps.contains(myself)) { apps.insert(myself); }
|
||||||
|
const bool ok = CFileUtils::writeStringToLockedFile(apps.toJsonString(), CFileUtils::appendFilePaths(swiftDataRoot(), "apps.json"));
|
||||||
|
if (!ok) { CLogMessage(static_cast<CApplication *>(nullptr)).error("Failed to write to application list file"); }
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
int CApplication::exec()
|
int CApplication::exec()
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(instance(), Q_FUNC_INFO, "missing application");
|
Q_ASSERT_X(instance(), Q_FUNC_INFO, "missing application");
|
||||||
|
CApplication::registerAsRunning();
|
||||||
CApplicationInfoList apps = getRunningApplications();
|
|
||||||
apps.push_back(instance()->getApplicationInfo());
|
|
||||||
bool ok = CFileUtils::writeStringToLockedFile(apps.toJsonString(), swiftDataRoot() + "apps.json");
|
|
||||||
if (!ok) { CLogMessage(static_cast<CApplication *>(nullptr)).error("Failed to write to application list file"); }
|
|
||||||
|
|
||||||
return QCoreApplication::exec();
|
return QCoreApplication::exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,6 +188,12 @@ namespace BlackCore
|
|||||||
return apps;
|
return apps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CApplication::isApplicationRunning(CApplicationInfo::Application application)
|
||||||
|
{
|
||||||
|
const CApplicationInfoList running = CApplication::getRunningApplications();
|
||||||
|
return running.containsApplication(application);
|
||||||
|
}
|
||||||
|
|
||||||
bool CApplication::isAlreadyRunning() const
|
bool CApplication::isAlreadyRunning() const
|
||||||
{
|
{
|
||||||
return getRunningApplications().containsBy([this](const CApplicationInfo & info) { return info.application() == getSwiftApplication(); });
|
return getRunningApplications().containsBy([this](const CApplicationInfo & info) { return info.application() == getSwiftApplication(); });
|
||||||
@@ -214,6 +226,34 @@ namespace BlackCore
|
|||||||
return CApplicationInfo::Unknown;
|
return CApplicationInfo::Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CApplication::getExecutableForApplication(CApplicationInfo::Application application) const
|
||||||
|
{
|
||||||
|
QString search;
|
||||||
|
switch (application)
|
||||||
|
{
|
||||||
|
case CApplicationInfo::PilotClientCore: search = "core"; break;
|
||||||
|
case CApplicationInfo::Laucher: search = "launcher"; break;
|
||||||
|
case CApplicationInfo::MappingTool: search = "data"; break;
|
||||||
|
case CApplicationInfo::PilotClientGui: search = "gui"; break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (search.isEmpty()) return "";
|
||||||
|
for (const QString &executable : CFileUtils::getSwiftExecutables())
|
||||||
|
{
|
||||||
|
if (!executable.contains("swift", Qt::CaseInsensitive)) { continue; }
|
||||||
|
if (executable.contains(search, Qt::CaseInsensitive)) { return executable; }
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CApplication::startLauncher()
|
||||||
|
{
|
||||||
|
static const QString launcher = CApplication::getExecutableForApplication(CApplicationInfo::Application::Laucher);
|
||||||
|
if (launcher.isEmpty() || CApplication::isApplicationRunning(CApplicationInfo::Laucher)) { return false; }
|
||||||
|
return QProcess::startDetached(launcher);
|
||||||
|
}
|
||||||
|
|
||||||
bool CApplication::isUnitTest() const
|
bool CApplication::isUnitTest() const
|
||||||
{
|
{
|
||||||
return this->m_unitTest;
|
return this->m_unitTest;
|
||||||
|
|||||||
@@ -113,6 +113,9 @@ namespace BlackCore
|
|||||||
//! Information about all running apps (including this one only if exec() has already been called)
|
//! Information about all running apps (including this one only if exec() has already been called)
|
||||||
static BlackMisc::CApplicationInfoList getRunningApplications();
|
static BlackMisc::CApplicationInfoList getRunningApplications();
|
||||||
|
|
||||||
|
//! Is application running?
|
||||||
|
static bool isApplicationRunning(BlackMisc::CApplicationInfo::Application application);
|
||||||
|
|
||||||
//! True if this swift application is already running (including different versions)
|
//! True if this swift application is already running (including different versions)
|
||||||
bool isAlreadyRunning() const;
|
bool isAlreadyRunning() const;
|
||||||
|
|
||||||
@@ -125,6 +128,12 @@ namespace BlackCore
|
|||||||
//! swift application running
|
//! swift application running
|
||||||
BlackMisc::CApplicationInfo::Application getSwiftApplication() const;
|
BlackMisc::CApplicationInfo::Application getSwiftApplication() const;
|
||||||
|
|
||||||
|
//! Executable names for the given applications
|
||||||
|
QString getExecutableForApplication(BlackMisc::CApplicationInfo::Application application) const;
|
||||||
|
|
||||||
|
//! Start the launcher
|
||||||
|
bool startLauncher();
|
||||||
|
|
||||||
//! Unit test?
|
//! Unit test?
|
||||||
bool isUnitTest() const;
|
bool isUnitTest() const;
|
||||||
|
|
||||||
@@ -199,6 +208,10 @@ namespace BlackCore
|
|||||||
//! Directory for temporary files
|
//! Directory for temporary files
|
||||||
QString getTemporaryDirectory() const;
|
QString getTemporaryDirectory() const;
|
||||||
|
|
||||||
|
//! Register as running
|
||||||
|
//! \note Normally done automatically when CApplication::exec is called
|
||||||
|
static bool registerAsRunning();
|
||||||
|
|
||||||
//! Run event loop
|
//! Run event loop
|
||||||
static int exec();
|
static int exec();
|
||||||
|
|
||||||
@@ -474,11 +487,11 @@ namespace BlackCore
|
|||||||
BlackMisc::CStatusMessageList initCrashHandler();
|
BlackMisc::CStatusMessageList initCrashHandler();
|
||||||
void crashDumpUploadEnabledChanged();
|
void crashDumpUploadEnabledChanged();
|
||||||
|
|
||||||
#ifdef BLACK_USE_CRASHPAD
|
#ifdef BLACK_USE_CRASHPAD
|
||||||
std::unique_ptr<crashpad::CrashpadClient> m_crashpadClient;
|
std::unique_ptr<crashpad::CrashpadClient> m_crashpadClient;
|
||||||
std::unique_ptr<crashpad::CrashReportDatabase> m_crashReportDatabase;
|
std::unique_ptr<crashpad::CrashReportDatabase> m_crashReportDatabase;
|
||||||
BlackMisc::CSettingReadOnly<BlackCore::Application::TCrashDumpUploadEnabled> m_crashDumpUploadEnabled { this, &CApplication::crashDumpUploadEnabledChanged };
|
BlackMisc::CSettingReadOnly<BlackCore::Application::TCrashDumpUploadEnabled> m_crashDumpUploadEnabled { this, &CApplication::crashDumpUploadEnabledChanged };
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
//! [SwiftApplicationDemo]
|
//! [SwiftApplicationDemo]
|
||||||
CGuiApplication::highDpiScreenSupport();
|
CGuiApplication::highDpiScreenSupport();
|
||||||
QApplication qa(argc, argv);
|
QApplication qa(argc, argv); // needed
|
||||||
|
Q_UNUSED(qa);
|
||||||
CGuiApplication a("swift launcher", CApplicationInfo::Laucher, CIcons::swiftLauncher1024());
|
CGuiApplication a("swift launcher", CApplicationInfo::Laucher, CIcons::swiftLauncher1024());
|
||||||
a.addParserOption({{"i", "installer"}, QCoreApplication::translate("main", "Installer setup."), "installer"});
|
a.addParserOption({{"i", "installer"}, QCoreApplication::translate("main", "Installer setup."), "installer"});
|
||||||
if (!a.parse()) { return EXIT_FAILURE; }
|
if (!a.parse()) { return EXIT_FAILURE; }
|
||||||
@@ -44,6 +45,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Dialog to decide external or internal core
|
// Dialog to decide external or internal core
|
||||||
CSwiftLauncher launcher;
|
CSwiftLauncher launcher;
|
||||||
|
CGuiApplication::registerAsRunning(); // needed because own exec is called
|
||||||
if (launcher.exec() == QDialog::Rejected) { return EXIT_SUCCESS; }
|
if (launcher.exec() == QDialog::Rejected) { return EXIT_SUCCESS; }
|
||||||
launcher.close();
|
launcher.close();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user