refact: return dbus error when application service's method failed

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe 2023-09-01 17:30:14 +08:00 committed by Comix
parent cb8b98c980
commit 70c7b92e0e

View File

@ -116,12 +116,16 @@ QDBusObjectPath ApplicationService::Launch(const QString &action, const QStringL
if (execStr.isEmpty()) { if (execStr.isEmpty()) {
auto Actions = m_entry->value(DesktopFileEntryKey, "Exec"); auto Actions = m_entry->value(DesktopFileEntryKey, "Exec");
if (!Actions) { if (!Actions) {
qWarning() << "application has isn't executable."; QString msg{"application can't be executed."};
qWarning() << msg;
sendErrorReply(QDBusError::Failed, msg);
return {}; return {};
} }
execStr = Actions->toString(ok); execStr = Actions->toString(ok);
if (!ok) { if (!ok) {
qWarning() << "default action value to string failed. abort..."; QString msg{"maybe entry actions's format is invalid, abort launch."};
qWarning() << msg;
sendErrorReply(QDBusError::Failed, msg);
return {}; return {};
} }
} }
@ -151,8 +155,10 @@ QDBusObjectPath ApplicationService::Launch(const QString &action, const QStringL
process.start(m_launcher, commands); process.start(m_launcher, commands);
process.waitForFinished(); process.waitForFinished();
if (auto code = process.exitCode(); code != 0) { if (auto code = process.exitCode(); code != 0) {
qWarning() << "Launch Application Failed. exitCode:" << code; auto msg = QString{"Launch Application Failed"};
return QString{""}; qWarning() << msg;
sendErrorReply(QDBusError::Failed, msg);
return {};
} }
return objectPath; return objectPath;
} }
@ -179,8 +185,10 @@ QDBusObjectPath ApplicationService::Launch(const QString &action, const QStringL
process.waitForFinished(); process.waitForFinished();
auto exitCode = process.exitCode(); auto exitCode = process.exitCode();
if (exitCode != 0) { if (exitCode != 0) {
qWarning() << "Launch Application Failed:" << binary << commands; auto msg = QString{"Launch Application Failed"};
return QString{""}; qWarning() << msg;
sendErrorReply(QDBusError::Failed, msg);
return {};
} }
return objectPath; return objectPath;
}, },
@ -203,6 +211,7 @@ bool ApplicationService::SendToDesktop() const noexcept
auto success = m_desktopSource.sourceFileRef().link(desktopFile); auto success = m_desktopSource.sourceFileRef().link(desktopFile);
if (!success) { if (!success) {
qDebug() << "create link failed:" << m_desktopSource.sourceFileRef().errorString() << "path:" << desktopFile; qDebug() << "create link failed:" << m_desktopSource.sourceFileRef().errorString() << "path:" << desktopFile;
sendErrorReply(QDBusError::ErrorType::Failed, m_desktopSource.sourceFileRef().errorString());
} }
return success; return success;
@ -225,6 +234,7 @@ bool ApplicationService::RemoveFromDesktop() const noexcept
if (!success) { if (!success) {
qDebug() << "remove desktop file failed:" << desktopFile.errorString(); qDebug() << "remove desktop file failed:" << desktopFile.errorString();
sendErrorReply(QDBusError::ErrorType::Failed, desktopFile.errorString());
} }
return success; return success;