diff --git a/apps/dde-am/src/commandexecutor.cpp b/apps/dde-am/src/commandexecutor.cpp index 47bd2ea1..f5bcbbe0 100644 --- a/apps/dde-am/src/commandexecutor.cpp +++ b/apps/dde-am/src/commandexecutor.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include DCORE_USE_NAMESPACE @@ -26,9 +28,27 @@ void registerComplexDbusType() } } -void CommandExecutor::setProgram(const QString &program) +bool CommandExecutor::setProgram(const QString &program) { - m_program = program; + if (program.isEmpty()) { + return false; + } + + // am requires the command to be a full path + if (!QDir::isAbsolutePath(program)) { + QString fullPath = QStandardPaths::findExecutable(program); + if (fullPath.isEmpty()) { + qWarning() << "Cannot find executable for command:" << program << ", skipping action invocation."; + return false; + } + + qDebug() << "Resolved command" << program << "to full path:" << fullPath; + m_program = fullPath; + } else { + m_program = program; + } + + return true; } void CommandExecutor::setArguments(const QStringList &arguments) diff --git a/apps/dde-am/src/commandexecutor.h b/apps/dde-am/src/commandexecutor.h index bc9ba1eb..f83da222 100644 --- a/apps/dde-am/src/commandexecutor.h +++ b/apps/dde-am/src/commandexecutor.h @@ -11,7 +11,7 @@ class CommandExecutor { public: - void setProgram(const QString &program); + bool setProgram(const QString &program); void setArguments(const QStringList &arguments); void setType(const QString &type); void setRunId(const QString &runId); diff --git a/apps/dde-am/src/main.cpp b/apps/dde-am/src/main.cpp index 6185358e..32f919c7 100644 --- a/apps/dde-am/src/main.cpp +++ b/apps/dde-am/src/main.cpp @@ -62,7 +62,9 @@ int handleExecuteCommand(const QCommandLineParser &parser, const QCommandLineOption &envOption) { CommandExecutor executor; - executor.setProgram(parser.value(executeOption)); + if (!executor.setProgram(parser.value(executeOption))) { + return -1; + } if (parser.isSet(typeOption)) { executor.setType(parser.value(typeOption));