Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions apps/dde-am/src/commandexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <QDBusConnection>
#include <QDBusMetaType>
#include <QDBusMessage>
#include <QDir>
#include <QStandardPaths>

DCORE_USE_NAMESPACE

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion apps/dde-am/src/commandexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion apps/dde-am/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down