feat: add impl of updateApplicationInfo
1. change the way to traverse files 2. refact some code Signed-off-by: ComixHe <heyuming@deepin.org> Signed-off-by: black-desk <me@black-desk.cn>
This commit is contained in:
@ -33,13 +33,20 @@ static ExitCode fromString(const std::string &str)
|
||||
{
|
||||
if (str == "done") {
|
||||
return ExitCode::Done;
|
||||
} else if (str == "canceled" or str == "timeout" or str == "failed" or str == "dependency" or str == "skipped") {
|
||||
}
|
||||
|
||||
if (str == "canceled" or str == "timeout" or str == "failed" or str == "dependency" or str == "skipped") {
|
||||
return ExitCode::SystemdError;
|
||||
} else if (str == "internalError") {
|
||||
}
|
||||
|
||||
if (str == "internalError") {
|
||||
return ExitCode::InternalError;
|
||||
} else if (str == "invalidInput") {
|
||||
}
|
||||
|
||||
if (str == "invalidInput") {
|
||||
return ExitCode::InvalidInput;
|
||||
}
|
||||
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
@ -71,8 +78,9 @@ static int processExecStart(msg_ptr &msg, const std::deque<std::string_view> &ex
|
||||
|
||||
if (ret = sd_bus_message_open_container(msg, SD_BUS_TYPE_VARIANT, "a(sasb)"); ret < 0) {
|
||||
sd_journal_perror("open variant of execStart failed.");
|
||||
if (auto tmp = sd_bus_message_close_container(msg))
|
||||
if (auto tmp = sd_bus_message_close_container(msg)) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret = sd_bus_message_open_container(msg, SD_BUS_TYPE_ARRAY, "(sasb)"); ret < 0) {
|
||||
@ -94,8 +102,9 @@ static int processExecStart(msg_ptr &msg, const std::deque<std::string_view> &ex
|
||||
sd_journal_perror("open array of execStart variant failed.");
|
||||
return ret;
|
||||
}
|
||||
for (std::size_t i = 0; i < execArgs.size(); ++i) {
|
||||
if (ret = sd_bus_message_append(msg, "s", execArgs[i].data()); ret < 0) {
|
||||
|
||||
for (auto execArg : execArgs) {
|
||||
if (ret = sd_bus_message_append(msg, "s", execArg.data()); ret < 0) {
|
||||
sd_journal_perror("append args of execStart failed.");
|
||||
return ret;
|
||||
}
|
||||
@ -211,11 +220,11 @@ static std::string cmdParse(msg_ptr &msg, std::deque<std::string_view> &&cmdLine
|
||||
if (ret = sd_bus_message_append(msg, "s", props["unitName"].data()); ret < 0) { // unitName
|
||||
sd_journal_perror("append unitName failed.");
|
||||
return serviceName;
|
||||
} else {
|
||||
serviceName = props["unitName"];
|
||||
props.erase("unitName");
|
||||
}
|
||||
|
||||
serviceName = props["unitName"];
|
||||
props.erase("unitName");
|
||||
|
||||
if (ret = sd_bus_message_append(msg, "s", "replace"); ret < 0) { // start mode
|
||||
sd_journal_perror("append startMode failed.");
|
||||
return serviceName;
|
||||
@ -271,11 +280,12 @@ int jobRemovedReceiver(sd_bus_message *m, void *userdata, sd_bus_error *ret_erro
|
||||
if (ret = sd_bus_error_is_set(ret_error); ret != 0) {
|
||||
sd_journal_print(LOG_ERR, "JobRemoved error: [%s,%s]", ret_error->name, ret_error->message);
|
||||
} else {
|
||||
const char *serviceId{nullptr}, *jobResult{nullptr};
|
||||
const char *serviceId{nullptr};
|
||||
const char *jobResult{nullptr};
|
||||
if (ret = sd_bus_message_read(m, "uoss", nullptr, nullptr, &serviceId, &jobResult); ret < 0) {
|
||||
sd_journal_perror("read from JobRemoved failed.");
|
||||
} else {
|
||||
auto ptr = reinterpret_cast<JobRemoveResult *>(userdata);
|
||||
auto *ptr = reinterpret_cast<JobRemoveResult *>(userdata);
|
||||
if (ptr->id == serviceId) {
|
||||
ptr->removedFlag = 1;
|
||||
ptr->result = fromString(jobResult);
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <QDir>
|
||||
#include "dbus/applicationmanager1service.h"
|
||||
#include "cgroupsidentifier.h"
|
||||
#include "global.h"
|
||||
|
||||
static void registerComplexDbusType()
|
||||
{
|
||||
@ -20,6 +19,7 @@ static void registerComplexDbusType()
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app{argc, argv};
|
||||
|
||||
auto &bus = ApplicationManager1DBus::instance();
|
||||
bus.initGlobalServerBus(DBusType::Session);
|
||||
bus.setDestBus("");
|
||||
@ -32,30 +32,24 @@ int main(int argc, char *argv[])
|
||||
XDGDataDirs = qgetenv("XDG_DATA_DIRS");
|
||||
if (XDGDataDirs.isEmpty()) {
|
||||
XDGDataDirs.append("/usr/local/share/:/usr/share/");
|
||||
qputenv("XDG_DATA_DIRS", XDGDataDirs);
|
||||
}
|
||||
auto desktopFileDirs = XDGDataDirs.split(':');
|
||||
auto desktopFileDirs = QString::fromLocal8Bit(XDGDataDirs).split(':', Qt::SkipEmptyParts);
|
||||
|
||||
for (const auto &dir : desktopFileDirs) {
|
||||
auto dirPath = QDir{QDir::cleanPath(dir) + "/applications"};
|
||||
if (!dirPath.exists()) {
|
||||
continue;
|
||||
std::for_each(desktopFileDirs.begin(), desktopFileDirs.end(), [](QString &str) {
|
||||
str = QDir::cleanPath(str) + QDir::separator() + "applications";
|
||||
});
|
||||
|
||||
applyIteratively(QList<QDir>(desktopFileDirs.begin(), desktopFileDirs.end()), [&AMService](const QFileInfo &info) -> bool {
|
||||
ParseError err{ParseError::NoError};
|
||||
auto ret = DesktopFile::searchDesktopFile(info.absoluteFilePath(), err);
|
||||
if (!ret.has_value()) {
|
||||
qWarning() << "failed to search File:" << err;
|
||||
return false;
|
||||
}
|
||||
QDirIterator it{dirPath.absolutePath(),
|
||||
{"*.desktop"},
|
||||
QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::Readable,
|
||||
QDirIterator::Subdirectories};
|
||||
while (it.hasNext()) {
|
||||
auto file = it.next();
|
||||
ParseError err;
|
||||
auto ret = DesktopFile::searchDesktopFile(file, err);
|
||||
if (!ret.has_value()) {
|
||||
continue;
|
||||
}
|
||||
if (!AMService.addApplication(std::move(ret).value())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
AMService.addApplication(std::move(ret).value());
|
||||
return false; // means to apply this function to the rest of the files
|
||||
});
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
Reference in New Issue
Block a user