mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 21:56:43 +08:00
Based on slack discussion, pass arguments from launcher to started application
https://swift-project.slack.com/archives/C04J6J76N/p1504449711000040 * utility functions in CApplication and CNetworkVatlib for cmd args * a.addVatlibOptions() in launcher * function CSwiftLauncher::startDetached to unify startup and simplify debugging
This commit is contained in:
committed by
Mathew Sutcliffe
parent
1baf74ebf3
commit
eab22e86b0
@@ -1156,6 +1156,18 @@ namespace BlackCore
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList CApplication::inheritedArguments(bool withVatlibArgs) const
|
||||
{
|
||||
QStringList args;
|
||||
if (this->isSet(m_cmdDevelopment))
|
||||
{
|
||||
args.append("--" + m_cmdDevelopment.names().first());
|
||||
args.append("true");
|
||||
}
|
||||
if (withVatlibArgs) { args.append(CNetworkVatlib::inheritedArguments()); }
|
||||
return args;
|
||||
}
|
||||
|
||||
void CApplication::cmdLineHelpMessage()
|
||||
{
|
||||
this->m_parser.showHelp(); // terminates
|
||||
|
||||
@@ -303,6 +303,9 @@ namespace BlackCore
|
||||
//! Display error message
|
||||
virtual bool cmdLineErrorMessage(const BlackMisc::CStatusMessageList &msgs, bool retry = false) const;
|
||||
|
||||
//! Arguments to be passed to another swift appplication
|
||||
QStringList inheritedArguments(bool withVatlibArgs = true) const;
|
||||
|
||||
// ----------------------- contexts ----------------------------------------
|
||||
|
||||
//! \name Context / core facade related
|
||||
|
||||
@@ -545,6 +545,17 @@ namespace BlackCore
|
||||
return m_interimPositionReceivers;
|
||||
}
|
||||
|
||||
QStringList CNetworkVatlib::inheritedArguments()
|
||||
{
|
||||
QStringList args;
|
||||
int id = 0;
|
||||
QString key;
|
||||
if (!getCmdLineClientIdAndKey(id, key)) return args;
|
||||
args << "--idAndKey";
|
||||
args << sApp->getParserValue("clientIdAndKey"); // as typed in
|
||||
return args;
|
||||
}
|
||||
|
||||
void CNetworkVatlib::sendServerQuery(const BlackMisc::Aviation::CCallsign &callsign)
|
||||
{
|
||||
Q_ASSERT_X(isConnected(), Q_FUNC_INFO, "Can't send to server when disconnected");
|
||||
@@ -710,9 +721,9 @@ namespace BlackCore
|
||||
return (CBuildConfig::isStableBranch() && !CBuildConfig::isDevBranch()) ? e : opts;
|
||||
}
|
||||
|
||||
bool CNetworkVatlib::getCmdLineClientIdAndKey(int &id, QString &key) const
|
||||
bool CNetworkVatlib::getCmdLineClientIdAndKey(int &id, QString &key)
|
||||
{
|
||||
QString clientIdAndKey = sApp->getParserValue("clientIdAndKey").toLower();
|
||||
const QString clientIdAndKey = sApp->getParserValue("clientIdAndKey").toLower();
|
||||
if (clientIdAndKey.isEmpty() || !clientIdAndKey.contains(':')) { return false; }
|
||||
const auto stringList = clientIdAndKey.split(':');
|
||||
QString clientIdAsString = stringList[0];
|
||||
|
||||
@@ -115,6 +115,9 @@ namespace BlackCore
|
||||
virtual const BlackMisc::Aviation::CCallsignSet &getInterimPositionReceivers() const override;
|
||||
//! @}
|
||||
|
||||
//! Arguments to be passed to another swift appplication
|
||||
static QStringList inheritedArguments();
|
||||
|
||||
//! \name Weather functions
|
||||
//! @{
|
||||
virtual void sendMetarQuery(const BlackMisc::Aviation::CAirportIcaoCode &airportIcao) override;
|
||||
@@ -127,7 +130,7 @@ namespace BlackCore
|
||||
static int const c_interimPositionTimeOffsetMsec = 2000; //!< offset time for received interim position updates
|
||||
|
||||
private:
|
||||
bool getCmdLineClientIdAndKey(int &id, QString &key) const;
|
||||
static bool getCmdLineClientIdAndKey(int &id, QString &key);
|
||||
|
||||
void replyToFrequencyQuery(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
void replyToNameQuery(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
@@ -34,6 +34,7 @@ int main(int argc, char *argv[])
|
||||
QApplication qa(argc, argv); // needed
|
||||
Q_UNUSED(qa);
|
||||
CGuiApplication a(CApplicationInfo::swiftLauncher(), CApplicationInfo::Laucher, CIcons::swiftLauncher1024());
|
||||
a.addVatlibOptions(); // so it can be passed to started applications
|
||||
a.addParserOption({{"i", "installer"}, QCoreApplication::translate("main", "Installer setup.") });
|
||||
if (!a.parseAndStartupCheck()) { return EXIT_FAILURE; }
|
||||
a.useWebDataServices(BlackCore::CWebReaderFlags::AllSwiftDbReaders, CDatabaseReaderConfigList::forLauncher());
|
||||
@@ -49,12 +50,6 @@ int main(int argc, char *argv[])
|
||||
CGuiApplication::registerAsRunning(); // needed because own exec is called
|
||||
if (launcher.exec() == QDialog::Rejected) { return EXIT_SUCCESS; }
|
||||
launcher.close();
|
||||
|
||||
const QString exe(launcher.getExecutable());
|
||||
const QStringList exeArgs(launcher.getExecutableArgs());
|
||||
Q_ASSERT_X(!exe.isEmpty(), Q_FUNC_INFO, "Missing executable");
|
||||
CLogMessage(QCoreApplication::instance()).info(launcher.getCmdLine());
|
||||
QProcess::startDetached(exe, exeArgs);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
const bool s = launcher.startDetached();
|
||||
return s ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,15 @@ CSwiftLauncher::~CSwiftLauncher()
|
||||
|
||||
QString CSwiftLauncher::getCmdLine() const
|
||||
{
|
||||
return toCmdLine(m_executable, m_executableArgs);
|
||||
return this->toCmdLine(m_executable, m_executableArgs);
|
||||
}
|
||||
|
||||
bool CSwiftLauncher::startDetached()
|
||||
{
|
||||
if (m_executable.isEmpty()) { return false; }
|
||||
const QString cmd = this->getCmdLine();
|
||||
CLogMessage(this).info(cmd);
|
||||
return QProcess::startDetached(m_executable, m_executableArgs);
|
||||
}
|
||||
|
||||
CEnableForFramelessWindow::WindowMode CSwiftLauncher::getWindowMode() const
|
||||
@@ -267,26 +275,20 @@ void CSwiftLauncher::startSwiftCore()
|
||||
args.append("--coreaudio");
|
||||
}
|
||||
|
||||
// I set this for debug purpose only
|
||||
args.append(sGui->inheritedArguments(true));
|
||||
m_executableArgs = args;
|
||||
m_executable.clear();
|
||||
m_executable = CDirectoryUtils::executableFilePath(CBuildConfig::swiftCoreExecutableName());
|
||||
CLogMessage(this).info(this->getCmdLine());
|
||||
|
||||
// start
|
||||
QProcess::startDetached(m_executable, m_executableArgs);
|
||||
this->startDetached();
|
||||
}
|
||||
|
||||
void CSwiftLauncher::setSwiftDataExecutable()
|
||||
{
|
||||
m_executable.clear();
|
||||
m_executable = CDirectoryUtils::executableFilePath(CBuildConfig::swiftDataExecutableName());
|
||||
m_executableArgs.clear();
|
||||
m_executableArgs = sGui->inheritedArguments(false);
|
||||
}
|
||||
|
||||
bool CSwiftLauncher::setSwiftGuiExecutable()
|
||||
{
|
||||
m_executable.clear();
|
||||
m_executable = CDirectoryUtils::executableFilePath(CBuildConfig::swiftGuiExecutableName());
|
||||
|
||||
QStringList args
|
||||
@@ -315,6 +317,7 @@ bool CSwiftLauncher::setSwiftGuiExecutable()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
args.append(sGui->inheritedArguments(true));
|
||||
m_executableArgs = args;
|
||||
return true;
|
||||
}
|
||||
@@ -399,11 +402,8 @@ bool CSwiftLauncher::warnAboutOtherSwiftApplications()
|
||||
QString CSwiftLauncher::toCmdLine(const QString &exe, const QStringList &exeArgs)
|
||||
{
|
||||
if (exeArgs.isEmpty()) { return exe; }
|
||||
QString cmd(exe);
|
||||
for (const QString &a : exeArgs)
|
||||
{
|
||||
cmd = cmd.append(" ").append(a);
|
||||
}
|
||||
const QString exeArgsString = exeArgs.join(' ');
|
||||
const QString cmd(exe + " " + exeArgsString);
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,10 @@ public:
|
||||
//! Current command line
|
||||
QString getCmdLine() const;
|
||||
|
||||
//! Start currently set application detached
|
||||
//! \remark simplifies debugging
|
||||
bool startDetached();
|
||||
|
||||
protected:
|
||||
//! \copydoc QDialog::mousePressEvent
|
||||
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||
|
||||
Reference in New Issue
Block a user