From da22cd0fc478ac69bd11d6ffcb9cecd20cce7cd7 Mon Sep 17 00:00:00 2001 From: yeshanshan Date: Thu, 13 Aug 2026 18:24:20 +0800 Subject: [PATCH] fix: treat system-directory apps as pre-installed when InstalledTime is missing When firstLaunch is false and InstalledTime record is null (e.g. after factory reset restores a pre-installed app's desktop file while storage.json is preserved), the old code unconditionally set InstalledTime to the current timestamp, causing uninstalled-and-restored pre-installed apps to incorrectly appear in the 'recently installed' list. Add helper isFromSystemApplicationsDir() to check whether the desktop source path belongs to a system-level applications directory (excluding user-level XDG_DATA_HOME). System-level apps now get InstalledTime = 0 (treated as pre-installed); user-level apps keep the current timestamp behavior. PMS: BUG-308223 Multica: https://agent-dev.uniontech.com/dde/issues/7c6f66c7-a8af-46c1-b59f-bed257e5e6d5 --- src/dbus/applicationservice.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/dbus/applicationservice.cpp b/src/dbus/applicationservice.cpp index e72b0588..75584e78 100644 --- a/src/dbus/applicationservice.cpp +++ b/src/dbus/applicationservice.cpp @@ -108,6 +108,22 @@ void unescapeEnvs(QVariantMap &options) noexcept options.insert(envKey, result); } +static bool isFromSystemApplicationsDir(const QString &sourcePath) +{ + const auto cleanSource = QDir::cleanPath(sourcePath); + const auto xdgDataHome = getXDGDataHome(); + for (const auto &dir : getApplicationsDirs()) { + if (dir.startsWith(xdgDataHome)) { + continue; // skip user-level directory + } + const auto cleanDir = QDir::cleanPath(dir) + QLatin1Char('/'); + if (cleanSource.startsWith(cleanDir)) { + return true; + } + } + return false; +} + } // namespace void ApplicationService::appendExtraEnvironments(QVariantMap &runtimeOptions) const noexcept @@ -237,7 +253,9 @@ ApplicationService::ApplicationService(DesktopFile source, } } else { if (value.isNull()) { - auto newInstalledTime = QDateTime::currentMSecsSinceEpoch(); + const auto newInstalledTime = isFromSystemApplicationsDir(m_desktopSource.sourcePath()) + ? 0 + : QDateTime::currentMSecsSinceEpoch(); if (!storagePtr->createApplicationValue( appId, fromStaticRaw(ApplicationPropertiesGroup), fromStaticRaw(InstalledTime), newInstalledTime)) { m_installedTime = -1;