Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkcore
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#394
  • Loading branch information
deepin-ci-robot committed Dec 14, 2023
1 parent 5e6a604 commit 041b631
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmake/DtkTools/DtkDBusMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function(dtk_add_dbus_interface _sources _interface _relativename)
set(_params -m)
endif()

get_source_file_property(_skipincludeannotations ${_interface} SKIP_INCLUDEANNOTATIONS)
get_source_file_property(_skipincludeannotations ${_interface} SKIP_INCLUDE_ANNOTATIONS)
if(_skipincludeannotations)
set(_params ${_params} -S)
endif()
Expand Down
4 changes: 2 additions & 2 deletions include/util/dutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ inline QString unescapeFromObjectPath(const QString &str)

inline QString getAppIdFromAbsolutePath(const QString &path)
{
decltype(auto) desktopSuffix = u8".desktop";
static QString desktopSuffix{u8".desktop"};
const auto &appDirs = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation);
if (!path.endsWith(desktopSuffix) or
!std::any_of(appDirs.cbegin(), appDirs.constEnd(), [&path](const QString &dir) { return path.startsWith(dir); })) {
return {};
}

auto tmp = path.chopped(sizeof(desktopSuffix) - 1);
auto tmp = path.chopped(desktopSuffix.size() - 1);
auto components = tmp.split(QDir::separator(), Qt::SkipEmptyParts);
auto location = std::find(components.cbegin(), components.cend(), "applications");
if (location == components.cend()) {
Expand Down
23 changes: 22 additions & 1 deletion src/dsgapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <QDBusReply>
#include <QRegularExpression>
#include <QLoggingCategory>
#include <QDBusConnectionInterface>

#include <DDBusInterface>

Expand All @@ -33,6 +34,19 @@ static inline QByteArray getSelfAppId() {
return DSGApplication::getId(QCoreApplication::applicationPid());
}

static bool isServiceActivatable(const QString &service)
{
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(service))
return false;

const QDBusReply<QStringList> activatableNames = QDBusConnection::sessionBus().interface()->
callWithArgumentList(QDBus::AutoDetect,
QLatin1String("ListActivatableNames"),
QList<QVariant>());

return activatableNames.value().contains(service);
}

QByteArray DSGApplication::id()
{
static QByteArray selfId = getSelfAppId();
Expand All @@ -52,6 +66,11 @@ QByteArray DSGApplication::id()

QByteArray DSGApplication::getId(qint64 pid)
{
if (!isServiceActivatable("org.desktopspec.ApplicationManager1")) {
qCInfo(dsgApp) << "Can't getId from AM for the " << pid << ", because AM is unavailable.";
return QByteArray();
}

int pidfd = syscall(SYS_pidfd_open, pid, 0);
if (pidfd < 0) {
qCWarning(dsgApp) << "pidfd open failed:" << strerror(errno);
Expand All @@ -69,7 +88,9 @@ QByteArray DSGApplication::getId(qint64 pid)
return QByteArray();
}

return reply.value().toLatin1();
const QByteArray appId = reply.value().toLatin1();
qCInfo(dsgApp) << "AppId is fetched from AM, and value is " << appId;
return appId;
}

DCORE_END_NAMESPACE
2 changes: 1 addition & 1 deletion tools/dci/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ bool exportTo(const QString &dciFile, const QString &targetDir) {
return false;

QMap<QString, QString> pathMap;
if (!copyFilesFromDci(&dci, newDir, "/", pathMap))
if (!copyFilesFromDci(&dci, QDir(newDir).absolutePath(), "/", pathMap))
return false;

// link to real source
Expand Down

0 comments on commit 041b631

Please sign in to comment.