fix: add wait mechanism for app icons#712
Conversation
qxp930712
commented
Feb 27, 2026
There was a problem hiding this comment.
Sorry @qxp930712, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
| , m_checkTimer(new QTimer(this)) | ||
| , m_checkCount(0) | ||
| { | ||
| m_checkTimer->setInterval(1000); // 1 second interval |
There was a problem hiding this comment.
| m_checkTimer->setInterval(1000); // 1 second interval | |
| m_checkTimer->setInterval(3000); // 3 second interval |
至少三秒吧,不然对于真的无效的 desktop 图标相当于要检查 60 次才会放弃
1. Implemented a pending check mechanism for app icons with absolute
paths
2. When an app is added, check if the icon file exists immediately
3. If the file is missing, place the app in a pending queue and start a
1-second timer
4. Periodically check pending items to see if the icon file has become
available
5. Added a 60-second timeout to force processing if files never appear
6. This resolves race conditions where app registration happens before
icon data is fully synchronized to disk or mounted
Log: Added delayed loading mechanism for application icons to handle
temporary file unavailability
Influence:
1. Install an application where the icon file exists immediately; verify
the icon displays instantly
2. Install an application where the icon file is missing at first but
appears within 60 seconds; verify the icon displays once the file is
detected
3. Install an application with a non-existent icon path; verify the
application is processed after the 60-second timeout
4. Test adding multiple applications with delayed icons simultaneously
5. Verify system resource usage and memory cleanup when the timer stops
PMS: BUG-347859
deepin pr auto review这段代码实现了一个对应用图标文件进行延迟检查的机制,主要目的是处理那些图标路径是绝对路径但文件尚未创建的情况(可能是应用安装过程中的竞态条件)。 以下是对这段 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进建议总结
修改后的代码片段建议针对第 1 和 第 2 点的建议: // appmgr.h
class AppMgr : public QObject
{
// ...
private:
static const int kCheckIntervalMs = 3000;
static const int kMaxCheckCount = 20;
// ...
};
// appmgr.cpp
void AppMgr::watchingAppItemAdded(const QString &key, AppItem *appItem)
{
// 如果已经在待处理列表中,先移除,避免重复或逻辑混乱
if (m_pendingAppItems.contains(key)) {
// 注意:这里可能需要根据业务逻辑决定是否要 delete 旧的 appItem
// 如果 AppMgr 拥有所有权,且 appItem 是新创建的,旧的可能需要 delete
// 但根据上下文,DBus 通知通常意味着是同一个对象,或者需要替换
// 简单起见,这里假设是替换引用
m_pendingAppItems.remove(key);
}
if (isAbsolutePathIcon(appItem->iconName)) {
QFileInfo fileInfo(appItem->iconName);
if (!fileInfo.exists()) {
m_pendingAppItems[key] = appItem;
if (!m_checkTimer->isActive()) {
m_checkCount = 0; // 开始新的等待周期时重置计数
m_checkTimer->start();
}
return;
}
}
m_appItems[key] = appItem;
watchingAppItemPropertyChanged(key, appItem);
Q_EMIT changed();
}
void AppMgr::checkPendingAppItems()
{
// 如果列表为空,停止计时器
if (m_pendingAppItems.isEmpty()) {
m_checkTimer->stop();
return;
}
m_checkCount++;
// ... 其余逻辑不变 ...
// 使用常量替代魔法数字
if (m_checkCount >= kMaxCheckCount && !m_pendingAppItems.isEmpty()) {
// ... 强制处理逻辑 ...
}
}总体而言,这段代码的修改是稳健的,能够解决实际问题,且没有引入明显的安全漏洞。主要的改进空间在于消除硬编码和增强边界条件的处理。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BLumia, qxp930712 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| } | ||
|
|
||
| // Check if timeout reached (60 seconds) | ||
| if (m_checkCount >= 20 && !m_pendingAppItems.isEmpty()) { |
There was a problem hiding this comment.
安装驱动后,会弹出一个继续的对话框,确认后才会创建图标链接,如果60s后才点击对话框的确认,那这个修改方式仍然存在问题呀,
对于填写的不是绝对路径的图标,这个也不能起作用了呀,
如果在60s内又卸载了这个应用,那60s之后它还会显示在启动器里么?