feat: add property installedTime,X-flatpak,X-linglong
Signed-off-by: black-desk <me@black-desk.cn>
This commit is contained in:
parent
c99a1b5d6a
commit
d1bdab899d
@ -7,6 +7,9 @@
|
||||
/>
|
||||
|
||||
<property name="Categories" type="as" access="read"/>
|
||||
<property name="X_linglong" type="b" access="read"/>
|
||||
<property name="X_Flatpak" type="b" access="read"/>
|
||||
<property name="installedTime" type="t" access="read"/>
|
||||
|
||||
<property name="Actions" type="as" access="read">
|
||||
<annotation
|
||||
|
@ -270,9 +270,9 @@ void ApplicationManager1Service::updateApplication(const QSharedPointer<Applicat
|
||||
return;
|
||||
}
|
||||
|
||||
auto mtime = getFileModifiedTime(desktopFile.sourceFileRef());
|
||||
auto mtime = getFileTimeInfo(desktopFile.sourceFileRef());
|
||||
|
||||
if (destApp->desktopFileSource().modified(mtime)) {
|
||||
if (destApp->desktopFileSource().modified(std::get<1>(mtime))) {
|
||||
auto *newEntry = new (std::nothrow) DesktopEntry{};
|
||||
if (newEntry == nullptr) {
|
||||
qCritical() << "new DesktopEntry failed.";
|
||||
|
@ -264,6 +264,23 @@ QString ApplicationService::id() const noexcept
|
||||
return m_desktopSource.desktopId();
|
||||
}
|
||||
|
||||
bool ApplicationService::x_Flatpak() const noexcept
|
||||
{
|
||||
auto val = findEntryValue(DesktopFileEntryKey, "X-flatpak", EntryValueType::String);
|
||||
return val.isNull();
|
||||
}
|
||||
|
||||
bool ApplicationService::x_linglong() const noexcept
|
||||
{
|
||||
auto val = findEntryValue(DesktopFileEntryKey, "X-linglong", EntryValueType::String);
|
||||
return val.isNull();
|
||||
}
|
||||
|
||||
qulonglong ApplicationService::installedTime() const noexcept
|
||||
{
|
||||
return m_desktopSource.createTime();
|
||||
}
|
||||
|
||||
qulonglong ApplicationService::lastLaunchedTime() const noexcept
|
||||
{
|
||||
return m_lastLaunch;
|
||||
|
@ -60,6 +60,15 @@ public:
|
||||
Q_PROPERTY(QList<QDBusObjectPath> Instances READ instances)
|
||||
[[nodiscard]] QList<QDBusObjectPath> instances() const noexcept;
|
||||
|
||||
Q_PROPERTY(bool X_Flatpak READ x_Flatpak)
|
||||
[[nodiscard]] bool x_Flatpak() const noexcept;
|
||||
|
||||
Q_PROPERTY(bool X_linglong READ x_linglong)
|
||||
[[nodiscard]] bool x_linglong() const noexcept;
|
||||
|
||||
Q_PROPERTY(qulonglong installedTime READ installedTime)
|
||||
[[nodiscard]] qulonglong installedTime() const noexcept;
|
||||
|
||||
[[nodiscard]] QDBusObjectPath findInstance(const QString &instanceId) const;
|
||||
|
||||
[[nodiscard]] const QString &getLauncher() const noexcept { return m_launcher; }
|
||||
|
@ -259,12 +259,12 @@ bool DesktopEntry::checkMainEntryValidation() const noexcept
|
||||
|
||||
std::optional<DesktopFile> DesktopFile::createTemporaryDesktopFile(std::unique_ptr<QFile> temporaryFile) noexcept
|
||||
{
|
||||
auto mtime = getFileModifiedTime(*temporaryFile);
|
||||
auto [ctime, mtime, _] = getFileTimeInfo(*temporaryFile);
|
||||
if (mtime == 0) {
|
||||
qWarning() << "create temporary file failed.";
|
||||
return std::nullopt;
|
||||
}
|
||||
return DesktopFile{std::move(temporaryFile), "", mtime};
|
||||
return DesktopFile{std::move(temporaryFile), "", mtime, ctime};
|
||||
}
|
||||
|
||||
std::optional<DesktopFile> DesktopFile::createTemporaryDesktopFile(const QString &temporaryFile) noexcept
|
||||
@ -330,7 +330,7 @@ std::optional<DesktopFile> DesktopFile::searchDesktopFileByPath(const QString &d
|
||||
|
||||
auto filePtr = std::make_unique<QFile>(std::move(path));
|
||||
|
||||
auto mtime = getFileModifiedTime(*filePtr);
|
||||
auto [ctime, mtime, _] = getFileTimeInfo(*filePtr);
|
||||
|
||||
if (mtime == 0) {
|
||||
err = DesktopErrorCode::OpenFailed;
|
||||
@ -338,7 +338,7 @@ std::optional<DesktopFile> DesktopFile::searchDesktopFileByPath(const QString &d
|
||||
}
|
||||
|
||||
err = DesktopErrorCode::NoError;
|
||||
return DesktopFile{std::move(filePtr), std::move(id), mtime};
|
||||
return DesktopFile{std::move(filePtr), std::move(id), mtime, ctime};
|
||||
}
|
||||
|
||||
std::optional<DesktopFile> DesktopFile::searchDesktopFileById(const QString &appId, DesktopErrorCode &err) noexcept
|
||||
|
@ -48,6 +48,7 @@ struct DesktopFile
|
||||
[[nodiscard]] QFile &sourceFileRef() const noexcept { return *m_fileSource; };
|
||||
[[nodiscard]] const QString &desktopId() const noexcept { return m_desktopId; }
|
||||
[[nodiscard]] bool modified(std::size_t time) const noexcept;
|
||||
[[nodiscard]] std::size_t createTime() const noexcept { return m_ctime; }
|
||||
|
||||
static std::optional<DesktopFile> searchDesktopFileById(const QString &appId, DesktopErrorCode &err) noexcept;
|
||||
static std::optional<DesktopFile> searchDesktopFileByPath(const QString &desktopFilePath, DesktopErrorCode &err) noexcept;
|
||||
@ -55,14 +56,16 @@ struct DesktopFile
|
||||
static std::optional<DesktopFile> createTemporaryDesktopFile(std::unique_ptr<QFile> temporaryFile) noexcept;
|
||||
|
||||
private:
|
||||
DesktopFile(std::unique_ptr<QFile> source, QString fileId, std::size_t mtime)
|
||||
DesktopFile(std::unique_ptr<QFile> source, QString fileId, std::size_t mtime, std::size_t ctime)
|
||||
: m_mtime(mtime)
|
||||
, m_ctime(ctime)
|
||||
, m_fileSource(std::move(source))
|
||||
, m_desktopId(std::move(fileId))
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t m_mtime;
|
||||
std::size_t m_ctime;
|
||||
std::unique_ptr<QFile> m_fileSource{nullptr};
|
||||
QString m_desktopId{""};
|
||||
};
|
||||
|
13
src/global.h
13
src/global.h
@ -467,7 +467,7 @@ ObjectMap dumpDBusObject(const QMap<QDBusObjectPath, QSharedPointer<T>> &map)
|
||||
return objs;
|
||||
}
|
||||
|
||||
inline std::size_t getFileModifiedTime(QFile &file)
|
||||
inline std::tuple<std::size_t, std::size_t, std::size_t> getFileTimeInfo(QFile &file)
|
||||
{
|
||||
struct stat buf;
|
||||
QFileInfo info{file};
|
||||
@ -475,17 +475,22 @@ inline std::size_t getFileModifiedTime(QFile &file)
|
||||
if (!file.isOpen()) {
|
||||
if (auto ret = file.open(QFile::ExistingOnly | QFile::ReadOnly | QFile::Text); !ret) {
|
||||
qWarning() << "open file" << info.absoluteFilePath() << "failed.";
|
||||
return 0;
|
||||
return std::make_tuple(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (auto ret = stat(info.absoluteFilePath().toLocal8Bit().data(), &buf); ret == -1) {
|
||||
qWarning() << "get file" << info.absoluteFilePath() << "state failed:" << std::strerror(errno);
|
||||
return 0;
|
||||
return std::make_tuple(0, 0, 0);
|
||||
}
|
||||
|
||||
constexpr std::size_t secToNano = 1e9;
|
||||
return buf.st_mtim.tv_sec * secToNano + buf.st_mtim.tv_nsec;
|
||||
|
||||
auto mtime = buf.st_mtim.tv_sec * secToNano + buf.st_mtim.tv_nsec;
|
||||
auto ctime = buf.st_ctim.tv_sec * secToNano + buf.st_ctim.tv_nsec;
|
||||
auto atime = buf.st_atim.tv_sec * secToNano + buf.st_atim.tv_nsec;
|
||||
|
||||
return std::make_tuple(ctime, mtime, atime);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
|
||||
m_am = new ApplicationManager1Service{std::make_unique<CGroupsIdentifier>(), bus.globalServerBus()};
|
||||
auto ptr = std::make_unique<QFile>(QString{"/usr/share/applications/test-Application.desktop"});
|
||||
DesktopFile file{std::move(ptr), "test-Application", 0};
|
||||
DesktopFile file{std::move(ptr), "test-Application", 0, 0};
|
||||
QSharedPointer<ApplicationService> app = QSharedPointer<ApplicationService>::create(std::move(file), nullptr);
|
||||
QSharedPointer<InstanceService> instance =
|
||||
QSharedPointer<InstanceService>::create(InstancePath.path().split('/').last(), ApplicationPath.path(), QString{"/"});
|
||||
|
Loading…
Reference in New Issue
Block a user