refactor: use CoreProcess::m_appPath to store app
This commit is contained in:
parent
8192d7b2d8
commit
087afd22b2
2 changed files with 15 additions and 21 deletions
|
|
@ -117,12 +117,6 @@ QString wrapIpv6(const QString &address)
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getAppFilePath(const QString &name)
|
|
||||||
{
|
|
||||||
QDir dir(QCoreApplication::applicationDirPath());
|
|
||||||
return dir.filePath(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CoreProcess
|
// CoreProcess
|
||||||
//
|
//
|
||||||
|
|
@ -131,6 +125,12 @@ CoreProcess::CoreProcess(const IServerConfig &serverConfig)
|
||||||
: m_serverConfig(serverConfig),
|
: m_serverConfig(serverConfig),
|
||||||
m_daemonIpcClient{new ipc::DaemonIpcClient(this)}
|
m_daemonIpcClient{new ipc::DaemonIpcClient(this)}
|
||||||
{
|
{
|
||||||
|
m_appPath = QStringLiteral("%1/%2").arg(QCoreApplication::applicationDirPath(), kCoreBinName);
|
||||||
|
if (!QFile::exists(m_appPath)) {
|
||||||
|
qFatal("core server binary does not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
connect(m_daemonIpcClient, &ipc::DaemonIpcClient::connected, this, &CoreProcess::daemonIpcClientConnected);
|
connect(m_daemonIpcClient, &ipc::DaemonIpcClient::connected, this, &CoreProcess::daemonIpcClientConnected);
|
||||||
connect(
|
connect(
|
||||||
m_daemonIpcClient, &ipc::DaemonIpcClient::connectionFailed, this, &CoreProcess::daemonIpcClientConnectionFailed
|
m_daemonIpcClient, &ipc::DaemonIpcClient::connectionFailed, this, &CoreProcess::daemonIpcClientConnectionFailed
|
||||||
|
|
@ -218,7 +218,7 @@ void CoreProcess::applyLogLevel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreProcess::startForegroundProcess(const QString &app, const QStringList &args)
|
void CoreProcess::startForegroundProcess(const QStringList &args)
|
||||||
{
|
{
|
||||||
using enum ProcessState;
|
using enum ProcessState;
|
||||||
|
|
||||||
|
|
@ -228,10 +228,10 @@ void CoreProcess::startForegroundProcess(const QString &app, const QStringList &
|
||||||
|
|
||||||
// only make quoted args for printing the command for convenience; so that the
|
// only make quoted args for printing the command for convenience; so that the
|
||||||
// core command can be easily copy/pasted to the terminal for testing.
|
// core command can be easily copy/pasted to the terminal for testing.
|
||||||
const auto quoted = makeQuotedArgs(app, args);
|
const auto quoted = makeQuotedArgs(m_appPath, args);
|
||||||
qInfo("running command: %s", qPrintable(quoted));
|
qInfo("running command: %s", qPrintable(quoted));
|
||||||
|
|
||||||
m_process->start(app, args);
|
m_process->start(m_appPath, args);
|
||||||
|
|
||||||
if (m_process->waitForStarted()) {
|
if (m_process->waitForStarted()) {
|
||||||
setProcessState(Started);
|
setProcessState(Started);
|
||||||
|
|
@ -241,13 +241,13 @@ void CoreProcess::startForegroundProcess(const QString &app, const QStringList &
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreProcess::startProcessFromDaemon(const QString &app, const QStringList &args)
|
void CoreProcess::startProcessFromDaemon(const QStringList &args)
|
||||||
{
|
{
|
||||||
if (m_processState != ProcessState::Starting) {
|
if (m_processState != ProcessState::Starting) {
|
||||||
qFatal("core process must be in starting state");
|
qFatal("core process must be in starting state");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString commandQuoted = makeQuotedArgs(app, args);
|
QString commandQuoted = makeQuotedArgs(m_appPath, args);
|
||||||
|
|
||||||
qInfo("running command: %s", qPrintable(commandQuoted));
|
qInfo("running command: %s", qPrintable(commandQuoted));
|
||||||
|
|
||||||
|
|
@ -358,12 +358,6 @@ void CoreProcess::start(std::optional<ProcessMode> processModeOption)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto app = getAppFilePath(kCoreBinName);
|
|
||||||
if (!QFile::exists(app)) {
|
|
||||||
qFatal("core server binary does not exist");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList args;
|
QStringList args;
|
||||||
|
|
||||||
addGenericArgs(args);
|
addGenericArgs(args);
|
||||||
|
|
@ -387,9 +381,9 @@ void CoreProcess::start(std::optional<ProcessMode> processModeOption)
|
||||||
qInfo().noquote() << "log file:" << Settings::value(Settings::Log::File).toString();
|
qInfo().noquote() << "log file:" << Settings::value(Settings::Log::File).toString();
|
||||||
|
|
||||||
if (processMode == ProcessMode::Desktop) {
|
if (processMode == ProcessMode::Desktop) {
|
||||||
startForegroundProcess(app, args);
|
startForegroundProcess(args);
|
||||||
} else if (processMode == ProcessMode::Service) {
|
} else if (processMode == ProcessMode::Service) {
|
||||||
startProcessFromDaemon(app, args);
|
startProcessFromDaemon(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_lastProcessMode = processMode;
|
m_lastProcessMode = processMode;
|
||||||
|
|
|
||||||
|
|
@ -111,8 +111,8 @@ private Q_SLOTS:
|
||||||
void daemonIpcClientConnected();
|
void daemonIpcClientConnected();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void startForegroundProcess(const QString &app, const QStringList &args);
|
void startForegroundProcess(const QStringList &args);
|
||||||
void startProcessFromDaemon(const QString &app, const QStringList &args);
|
void startProcessFromDaemon(const QStringList &args);
|
||||||
void stopForegroundProcess() const;
|
void stopForegroundProcess() const;
|
||||||
void stopProcessFromDaemon();
|
void stopProcessFromDaemon();
|
||||||
bool addGenericArgs(QStringList &args) const;
|
bool addGenericArgs(QStringList &args) const;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue