Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 86 additions & 1 deletion src/ddeintegration/appmgr.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -127,7 +127,11 @@ AppMgr::AppMgr(QObject *parent)
, m_objectManager(new AppManager1ApplicationObjectManager("org.desktopspec.ApplicationManager1",
"/org/desktopspec/ApplicationManager1",
QDBusConnection::sessionBus(), this))
, m_checkTimer(new QTimer(this))
, m_checkCount(0)
{
m_checkTimer->setInterval(3000); // 3 second interval
connect(m_checkTimer, &QTimer::timeout, this, &AppMgr::checkPendingAppItems);
initObjectManager();
}

Expand Down Expand Up @@ -430,6 +434,8 @@ void AppMgr::initObjectManager()
qWarning() << "App already exists for the path:" << key;
return;
}
// Reset check count when new app is added
m_checkCount = 0;
if (auto appItem = parseDBus2AppItem(interfacesAndProperties)) {
qCDebug(logDdeIntegration) << "App item added, desktopId" << appItem->id;
watchingAppItemAdded(key, appItem);
Expand Down Expand Up @@ -503,6 +509,22 @@ void AppMgr::fetchAppItems()

void AppMgr::watchingAppItemAdded(const QString &key, AppItem *appItem)
{
// Check if iconName is an absolute path and if the file exists
if (isAbsolutePathIcon(appItem->iconName)) {
QFileInfo fileInfo(appItem->iconName);
if (!fileInfo.exists()) {
// File doesn't exist, add to pending container
m_pendingAppItems[key] = appItem;

// Start timer if not already running
if (!m_checkTimer->isActive()) {
m_checkTimer->start();
}
return;
}
}

// Icon exists or is a system icon, proceed with normal logic
m_appItems[key] = appItem;
watchingAppItemPropertyChanged(key, appItem);
Q_EMIT changed();
Expand All @@ -527,6 +549,69 @@ void AppMgr::watchingAppItemRemoved(const QString &key)
Q_EMIT changed();
}

void AppMgr::checkPendingAppItems()
{
m_checkCount++;
if (m_pendingAppItems.isEmpty()) {
m_checkTimer->stop();
return;
}

QList<QPair<QString, AppItem *>> itemsToProcess;

// Check all pending items
for (auto it = m_pendingAppItems.begin(); it != m_pendingAppItems.end(); ) {
const QString &key = it.key();
AppItem *appItem = it.value();

if (isAbsolutePathIcon(appItem->iconName)) {
QFileInfo fileInfo(appItem->iconName);
if (fileInfo.exists()) {
// File now exists, add to main container
itemsToProcess.append(qMakePair(key, appItem));
it = m_pendingAppItems.erase(it);
continue;
}
}
++it;
}

// Process items whose icons now exist
for (const auto &itemPair : itemsToProcess) {
const QString &key = itemPair.first;
AppItem *appItem = itemPair.second;

m_appItems[key] = appItem;
watchingAppItemPropertyChanged(key, appItem);
Q_EMIT changed();
}

// Check if timeout reached (60 seconds)
if (m_checkCount >= 20 && !m_pendingAppItems.isEmpty()) {
Copy link
Copy Markdown
Contributor

@18202781743 18202781743 Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

安装驱动后,会弹出一个继续的对话框,确认后才会创建图标链接,如果60s后才点击对话框的确认,那这个修改方式仍然存在问题呀,
对于填写的不是绝对路径的图标,这个也不能起作用了呀,
如果在60s内又卸载了这个应用,那60s之后它还会显示在启动器里么?

// Force process all remaining pending items
for (auto it = m_pendingAppItems.begin(); it != m_pendingAppItems.end(); ) {
const QString &key = it.key();
AppItem *appItem = it.value();

m_appItems[key] = appItem;
watchingAppItemPropertyChanged(key, appItem);
Q_EMIT changed();

it = m_pendingAppItems.erase(it);
}

m_checkTimer->stop();
} else if (m_pendingAppItems.isEmpty()) {
m_checkTimer->stop();
}
}

bool AppMgr::isAbsolutePathIcon(const QString &iconName) const
{
// Check if the icon name is an absolute path (starts with /)
return iconName.startsWith('/');
}

AppMgr *AppMgr::instance() {
static AppMgr gInstance;
return &gInstance;
Expand Down
11 changes: 10 additions & 1 deletion src/ddeintegration/appmgr.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <QMap>

Check warning on line 7 in src/ddeintegration/appmgr.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMap> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QObject>

Check warning on line 8 in src/ddeintegration/appmgr.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPointer>

Check warning on line 9 in src/ddeintegration/appmgr.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPointer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTimer>

Check warning on line 10 in src/ddeintegration/appmgr.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFileInfo>

Check warning on line 11 in src/ddeintegration/appmgr.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFileInfo> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dtkcore_global.h>

Check warning on line 12 in src/ddeintegration/appmgr.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dtkcore_global.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DCORE_BEGIN_NAMESPACE
class DConfig;
Expand Down Expand Up @@ -56,15 +58,22 @@
void changed();
void itemDataChanged(const QString &id);

private slots:

Check warning on line 61 in src/ddeintegration/appmgr.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.
void checkPendingAppItems();

private:
void initObjectManager();
void fetchAppItems();
void watchingAppItemAdded(const QString &key, AppMgr::AppItem *appItem);
void watchingAppItemRemoved(const QString &key);
void watchingAppItemPropertyChanged(const QString &key, AppMgr::AppItem *appItem);
void updateAppsLaunchedTimes(const QVariantMap &appsLaunchedTimes);
bool isAbsolutePathIcon(const QString &iconName) const;

private:
__AppManager1ApplicationObjectManager *m_objectManager;
QMap<QString, AppMgr::AppItem *> m_appItems;
QMap<QString, AppMgr::AppItem *> m_pendingAppItems;
QTimer *m_checkTimer;
int m_checkCount;
};