mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 02:35:38 +08:00
Ref T210, adjusting application class
* unit test flag is redundant * added own distribution
This commit is contained in:
@@ -122,10 +122,8 @@ namespace BlackCore
|
|||||||
QCoreApplication::setApplicationName(m_applicationName);
|
QCoreApplication::setApplicationName(m_applicationName);
|
||||||
QCoreApplication::setApplicationVersion(CBuildConfig::getVersionString());
|
QCoreApplication::setApplicationVersion(CBuildConfig::getVersionString());
|
||||||
this->setObjectName(m_applicationName);
|
this->setObjectName(m_applicationName);
|
||||||
const QString executable = QFileInfo(QCoreApplication::applicationFilePath()).fileName();
|
if (this->getApplicationInfo().application() == CApplicationInfo::UnitTest)
|
||||||
if (executable.startsWith("test"))
|
|
||||||
{
|
{
|
||||||
m_unitTest = true;
|
|
||||||
const QString tempPath(this->getTemporaryDirectory());
|
const QString tempPath(this->getTemporaryDirectory());
|
||||||
BlackMisc::setMockCacheRootDirectory(tempPath);
|
BlackMisc::setMockCacheRootDirectory(tempPath);
|
||||||
}
|
}
|
||||||
@@ -224,10 +222,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
CApplicationInfo CApplication::getApplicationInfo() const
|
CApplicationInfo CApplication::getApplicationInfo() const
|
||||||
{
|
{
|
||||||
CApplicationInfo::ApplicationMode mode = CApplicationInfo::None;
|
return { CApplication::getSwiftApplication(), QCoreApplication::applicationFilePath(), CBuildConfig::getVersionString(), CProcessInfo::currentProcess() };
|
||||||
if (isRunningInDeveloperEnvironment()) { mode |= CApplicationInfo::Developer; }
|
|
||||||
if (CBuildConfig::isDevBranch()) { mode |= CApplicationInfo::BetaTest; }
|
|
||||||
return { CApplication::getSwiftApplication(), mode, QCoreApplication::applicationFilePath(), CBuildConfig::getVersionString(), CProcessInfo::currentProcess() };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CApplicationInfoList CApplication::getRunningApplications()
|
CApplicationInfoList CApplication::getRunningApplications()
|
||||||
@@ -273,7 +268,6 @@ namespace BlackCore
|
|||||||
|
|
||||||
CApplicationInfo::Application CApplication::getSwiftApplication() const
|
CApplicationInfo::Application CApplication::getSwiftApplication() const
|
||||||
{
|
{
|
||||||
if (this->isUnitTest()) { return CApplicationInfo::UnitTest; }
|
|
||||||
if (m_application != CApplicationInfo::Unknown) { return m_application; }
|
if (m_application != CApplicationInfo::Unknown) { return m_application; }
|
||||||
|
|
||||||
// if not set, guess
|
// if not set, guess
|
||||||
@@ -297,10 +291,9 @@ namespace BlackCore
|
|||||||
case CApplicationInfo::Laucher: search = "launcher"; break;
|
case CApplicationInfo::Laucher: search = "launcher"; break;
|
||||||
case CApplicationInfo::MappingTool: search = "data"; break;
|
case CApplicationInfo::MappingTool: search = "data"; break;
|
||||||
case CApplicationInfo::PilotClientGui: search = "gui"; break;
|
case CApplicationInfo::PilotClientGui: search = "gui"; break;
|
||||||
default:
|
default: break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (search.isEmpty()) return "";
|
if (search.isEmpty()) { return ""; }
|
||||||
for (const QString &executable : CFileUtils::getSwiftExecutables())
|
for (const QString &executable : CFileUtils::getSwiftExecutables())
|
||||||
{
|
{
|
||||||
if (!executable.contains("swift", Qt::CaseInsensitive)) { continue; }
|
if (!executable.contains("swift", Qt::CaseInsensitive)) { continue; }
|
||||||
@@ -327,11 +320,6 @@ namespace BlackCore
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CApplication::isUnitTest() const
|
|
||||||
{
|
|
||||||
return m_unitTest;
|
|
||||||
}
|
|
||||||
|
|
||||||
CGlobalSetup CApplication::getGlobalSetup() const
|
CGlobalSetup CApplication::getGlobalSetup() const
|
||||||
{
|
{
|
||||||
if (m_shutdown) { return CGlobalSetup(); }
|
if (m_shutdown) { return CGlobalSetup(); }
|
||||||
@@ -348,6 +336,13 @@ namespace BlackCore
|
|||||||
return r->getUpdateInfo();
|
return r->getUpdateInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CDistribution CApplication::getOwnDistribution() const
|
||||||
|
{
|
||||||
|
if (CBuildConfig::isLocalDeveloperDebugBuild()) { return CDistribution::localDeveloperBuild(); }
|
||||||
|
const CUpdateInfo u = this->getUpdateInfo();
|
||||||
|
return u.anticipateOwnDistribution();
|
||||||
|
}
|
||||||
|
|
||||||
bool CApplication::start()
|
bool CApplication::start()
|
||||||
{
|
{
|
||||||
m_started = false; // reset
|
m_started = false; // reset
|
||||||
@@ -459,16 +454,10 @@ namespace BlackCore
|
|||||||
|
|
||||||
CStatusMessageList CApplication::requestReloadOfSetupAndVersion()
|
CStatusMessageList CApplication::requestReloadOfSetupAndVersion()
|
||||||
{
|
{
|
||||||
if (!m_shutdown)
|
if (m_shutdown) { return CStatusMessage(this).warning("Shutting down, not reading"); }
|
||||||
{
|
if (!m_setupReader) { return CStatusMessage(this).error("No reader for setup/version"); }
|
||||||
Q_ASSERT_X(m_setupReader, Q_FUNC_INFO, "Missing reader");
|
Q_ASSERT_X(m_parsed, Q_FUNC_INFO, "Not yet parsed");
|
||||||
Q_ASSERT_X(m_parsed, Q_FUNC_INFO, "Not yet parsed");
|
return m_setupReader->asyncLoad();
|
||||||
return m_setupReader->asyncLoad();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return CStatusMessage(this).error("No reader for setup/version");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CApplication::hasWebDataServices() const
|
bool CApplication::hasWebDataServices() const
|
||||||
@@ -493,9 +482,9 @@ namespace BlackCore
|
|||||||
|
|
||||||
const QString &CApplication::versionStringDetailed() const
|
const QString &CApplication::versionStringDetailed() const
|
||||||
{
|
{
|
||||||
if (isRunningInDeveloperEnvironment() && CBuildConfig::isDevBranch())
|
if (this->isRunningInDeveloperEnvironment() && CBuildConfig::isLocalDeveloperDebugBuild())
|
||||||
{
|
{
|
||||||
static const QString s(CBuildConfig::getVersionString() + " [dev,DEV]");
|
static const QString s(CBuildConfig::getVersionString() + " [dev,DEVDBG]");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
if (isRunningInDeveloperEnvironment())
|
if (isRunningInDeveloperEnvironment())
|
||||||
@@ -503,9 +492,9 @@ namespace BlackCore
|
|||||||
static const QString s(CBuildConfig::getVersionString() + " [dev]");
|
static const QString s(CBuildConfig::getVersionString() + " [dev]");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
if (CBuildConfig::isDevBranch())
|
if (CBuildConfig::isLocalDeveloperDebugBuild())
|
||||||
{
|
{
|
||||||
static const QString s(CBuildConfig::getVersionString() + " [DEV]");
|
static const QString s(CBuildConfig::getVersionString() + " [DEVDBG]");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
return CBuildConfig::getVersionString();
|
return CBuildConfig::getVersionString();
|
||||||
@@ -525,9 +514,12 @@ namespace BlackCore
|
|||||||
|
|
||||||
bool CApplication::initIsRunningInDeveloperEnvironment() const
|
bool CApplication::initIsRunningInDeveloperEnvironment() const
|
||||||
{
|
{
|
||||||
if (!CBuildConfig::canRunInDeveloperEnvironment()) { return false; }
|
// assumption: restricted distributions are development versions
|
||||||
if (m_unitTest) { return true; }
|
|
||||||
if (this->isSet(m_cmdDevelopment)) { return true; }
|
if (this->getApplicationInfo().isSampleOrUnitTest()) { return true; }
|
||||||
|
const CDistribution d(this->getOwnDistribution());
|
||||||
|
const bool canSetDeveloperEnv = CBuildConfig::isLocalDeveloperDebugBuild() || d.isRestricted();
|
||||||
|
if (canSetDeveloperEnv && this->isSet(m_cmdDevelopment)) { return true; }
|
||||||
if (this->isSetupAvailable())
|
if (this->isSetupAvailable())
|
||||||
{
|
{
|
||||||
// assume value from setup
|
// assume value from setup
|
||||||
@@ -536,35 +528,6 @@ namespace BlackCore
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CApplication::setSignalStartupAutomatically(bool enabled)
|
|
||||||
{
|
|
||||||
m_signalStartup = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CApplication::getEnvironmentInfoString(const QString &separator) const
|
|
||||||
{
|
|
||||||
const QString env =
|
|
||||||
QLatin1String("Beta: ") %
|
|
||||||
boolToYesNo(CBuildConfig::isDevBranch()) %
|
|
||||||
QLatin1String(" dev.env.: ") %
|
|
||||||
boolToYesNo(this->isRunningInDeveloperEnvironment()) %
|
|
||||||
separator %
|
|
||||||
QLatin1String("Windows NT: ") %
|
|
||||||
boolToYesNo(CBuildConfig::isRunningOnWindowsNtPlatform()) %
|
|
||||||
QLatin1String(" Windows 10: ") %
|
|
||||||
boolToYesNo(CBuildConfig::isRunningOnWindows10()) %
|
|
||||||
separator %
|
|
||||||
QLatin1String("Linux: ") %
|
|
||||||
boolToYesNo(CBuildConfig::isRunningOnLinuxPlatform()) %
|
|
||||||
QLatin1String(" Unix: ") %
|
|
||||||
boolToYesNo(CBuildConfig::isRunningOnUnixPlatform()) %
|
|
||||||
separator %
|
|
||||||
QLatin1String("MacOS: ") %
|
|
||||||
boolToYesNo(CBuildConfig::isRunningOnMacOSPlatform());
|
|
||||||
|
|
||||||
return env;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CApplication::hasUnsavedSettings() const
|
bool CApplication::hasUnsavedSettings() const
|
||||||
{
|
{
|
||||||
return !this->getUnsavedSettingsKeys().isEmpty();
|
return !this->getUnsavedSettingsKeys().isEmpty();
|
||||||
@@ -603,7 +566,27 @@ namespace BlackCore
|
|||||||
CBuildConfig::getVersionString() %
|
CBuildConfig::getVersionString() %
|
||||||
QLatin1Char(' ') % (CBuildConfig::isReleaseBuild() ? QLatin1String("Release build") : QLatin1String("Debug build")) %
|
QLatin1Char(' ') % (CBuildConfig::isReleaseBuild() ? QLatin1String("Release build") : QLatin1String("Debug build")) %
|
||||||
separator %
|
separator %
|
||||||
getEnvironmentInfoString(separator) %
|
QLatin1String("Local dev.dbg.: ") %
|
||||||
|
boolToYesNo(CBuildConfig::isLocalDeveloperDebugBuild()) %
|
||||||
|
separator %
|
||||||
|
QLatin1String("dev.env.: ") %
|
||||||
|
boolToYesNo(this->isRunningInDeveloperEnvironment()) %
|
||||||
|
separator %
|
||||||
|
QLatin1String("distribution: ") %
|
||||||
|
this->getOwnDistribution().toQString(true) %
|
||||||
|
separator %
|
||||||
|
QLatin1String("Windows NT: ") %
|
||||||
|
boolToYesNo(CBuildConfig::isRunningOnWindowsNtPlatform()) %
|
||||||
|
QLatin1String(" Windows 10: ") %
|
||||||
|
boolToYesNo(CBuildConfig::isRunningOnWindows10()) %
|
||||||
|
separator %
|
||||||
|
QLatin1String("Linux: ") %
|
||||||
|
boolToYesNo(CBuildConfig::isRunningOnLinuxPlatform()) %
|
||||||
|
QLatin1String(" Unix: ") %
|
||||||
|
boolToYesNo(CBuildConfig::isRunningOnUnixPlatform()) %
|
||||||
|
separator %
|
||||||
|
QLatin1String("MacOS: ") %
|
||||||
|
boolToYesNo(CBuildConfig::isRunningOnMacOSPlatform()) %
|
||||||
separator %
|
separator %
|
||||||
QLatin1String("Build Abi: ") %
|
QLatin1String("Build Abi: ") %
|
||||||
QSysInfo::buildAbi() %
|
QSysInfo::buildAbi() %
|
||||||
@@ -612,6 +595,7 @@ namespace BlackCore
|
|||||||
QSysInfo::buildCpuArchitecture() %
|
QSysInfo::buildCpuArchitecture() %
|
||||||
separator %
|
separator %
|
||||||
CBuildConfig::compiledWithInfo(false);
|
CBuildConfig::compiledWithInfo(false);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -763,10 +747,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CApplication::exit(int retcode)
|
void CApplication::exit(int retcode)
|
||||||
{
|
{
|
||||||
if (instance())
|
if (instance()) { instance()->gracefulShutdown(); }
|
||||||
{
|
|
||||||
instance()->gracefulShutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
// when the event loop is not running, this does nothing
|
// when the event loop is not running, this does nothing
|
||||||
QCoreApplication::exit(retcode);
|
QCoreApplication::exit(retcode);
|
||||||
@@ -1474,7 +1455,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
#ifdef BLACK_USE_CRASHPAD
|
#ifdef BLACK_USE_CRASHPAD
|
||||||
// No crash handling for unit tests
|
// No crash handling for unit tests
|
||||||
if (isUnitTest()) { return CStatusMessage(this).info("No crash handler for unit tests"); }
|
if (this->getApplicationInfo().isUnitTest()) { return CStatusMessage(this).info("No crash handler for unit tests"); }
|
||||||
|
|
||||||
static const QString crashpadHandler(CBuildConfig::isRunningOnWindowsNtPlatform() ? "swift_crashpad_handler.exe" : "swift_crashpad_handler");
|
static const QString crashpadHandler(CBuildConfig::isRunningOnWindowsNtPlatform() ? "swift_crashpad_handler.exe" : "swift_crashpad_handler");
|
||||||
static const QString handler = CFileUtils::appendFilePaths(CDirectoryUtils::binDirectory(), crashpadHandler);
|
static const QString handler = CFileUtils::appendFilePaths(CDirectoryUtils::binDirectory(), crashpadHandler);
|
||||||
|
|||||||
@@ -147,9 +147,6 @@ namespace BlackCore
|
|||||||
//! Start the launcher and quit
|
//! Start the launcher and quit
|
||||||
bool startLauncherAndQuit();
|
bool startLauncherAndQuit();
|
||||||
|
|
||||||
//! Unit test?
|
|
||||||
bool isUnitTest() const;
|
|
||||||
|
|
||||||
//! Global setup
|
//! Global setup
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
BlackCore::Data::CGlobalSetup getGlobalSetup() const;
|
BlackCore::Data::CGlobalSetup getGlobalSetup() const;
|
||||||
@@ -158,6 +155,10 @@ namespace BlackCore
|
|||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
BlackMisc::Db::CUpdateInfo getUpdateInfo() const;
|
BlackMisc::Db::CUpdateInfo getUpdateInfo() const;
|
||||||
|
|
||||||
|
//! Own distribution
|
||||||
|
//! \threadsafe
|
||||||
|
BlackMisc::Db::CDistribution getOwnDistribution() const;
|
||||||
|
|
||||||
//! Delete all cookies from cookie manager
|
//! Delete all cookies from cookie manager
|
||||||
void deleteAllCookies();
|
void deleteAllCookies();
|
||||||
|
|
||||||
@@ -226,12 +227,9 @@ namespace BlackCore
|
|||||||
bool isRunningInDeveloperEnvironment() const { return m_devEnv; }
|
bool isRunningInDeveloperEnvironment() const { return m_devEnv; }
|
||||||
|
|
||||||
//! Signal startup automatically or individually
|
//! Signal startup automatically or individually
|
||||||
void setSignalStartupAutomatically(bool enabled);
|
void setSignalStartupAutomatically(bool enabled) { m_signalStartup = enabled; }
|
||||||
|
|
||||||
//! Info string
|
//! Comprehensive info
|
||||||
QString getEnvironmentInfoString(const QString &separator) const;
|
|
||||||
|
|
||||||
//! To string
|
|
||||||
QString getInfoString(const QString &separator) const;
|
QString getInfoString(const QString &separator) const;
|
||||||
|
|
||||||
//! Unsaved settings
|
//! Unsaved settings
|
||||||
@@ -577,7 +575,7 @@ namespace BlackCore
|
|||||||
//! Init parser
|
//! Init parser
|
||||||
void initParser();
|
void initParser();
|
||||||
|
|
||||||
//! Dev.environment
|
//! Dev.environment, return value will be used for m_devEnv
|
||||||
bool initIsRunningInDeveloperEnvironment() const;
|
bool initIsRunningInDeveloperEnvironment() const;
|
||||||
|
|
||||||
//! Async. start when setup is loaded
|
//! Async. start when setup is loaded
|
||||||
@@ -609,7 +607,6 @@ namespace BlackCore
|
|||||||
bool m_useWebData = false; //!< use web data
|
bool m_useWebData = false; //!< use web data
|
||||||
bool m_signalStartup = true; //!< signal startup automatically
|
bool m_signalStartup = true; //!< signal startup automatically
|
||||||
bool m_devEnv = false; //!< dev. environment
|
bool m_devEnv = false; //!< dev. environment
|
||||||
bool m_unitTest = false; //!< is UNIT test
|
|
||||||
bool m_autoSaveSettings = true; //!< automatically saving all settings
|
bool m_autoSaveSettings = true; //!< automatically saving all settings
|
||||||
|
|
||||||
// -------------- crashpad -----------------
|
// -------------- crashpad -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user