fix: 修复任务栏显示图标为齿轮的问题

当获取图标为齿轮时,会在之后的半分钟内反复获取图标,这时,图标可能还没有放在指定的位置,所以显示异常,还有可能是qt内部的缓存机制导致的,第一次获取图标异常,后面不再尝试获取。

Log: 修复任务栏显示图标为齿轮的问题
Bug: https://pms.uniontech.com/zentao/bug-view-22246.html
Change-Id: I281077c59906bcb1e387dc0cf9054cddb03f5ed2
This commit is contained in:
Fan PengCheng 2021-04-26 15:12:17 +08:00 committed by fanpengcheng
parent 110c4966b1
commit 32014afc27
2 changed files with 11 additions and 4 deletions

View File

@ -88,7 +88,7 @@ AppItem::AppItem(const QGSettings *appSettings, const QGSettings *activeAppSetti
m_updateIconGeometryTimer->setInterval(500);
m_updateIconGeometryTimer->setSingleShot(true);
m_retryObtainIconTimer->setInterval(500);
m_retryObtainIconTimer->setInterval(3000);
m_retryObtainIconTimer->setSingleShot(true);
m_refershIconTimer->setInterval(1000);
@ -610,14 +610,18 @@ void AppItem::refreshIcon()
}
if (!m_iconValid) {
if (m_retryTimes < 5) {
if (m_retryTimes < 10) {
m_retryTimes++;
qDebug() << m_itemEntryInter->name() << "obtain app icon(" << icon << ")failed, retry times:" << m_retryTimes;
// Maybe the icon was installed after we loaded the caches.
// QIcon::setThemeSearchPaths will force Qt to re-check the gtk cache validity.
QIcon::setThemeSearchPaths(QIcon::themeSearchPaths());
m_retryObtainIconTimer->start();
} else {
// 如果图标获取失败没隔10秒刷新一次
// 如果图标获取失败,一分钟后再自动刷新一次(如果还是显示异常,基本需要应用自身看下为什么了)
if (!m_iconValid)
QTimer::singleShot(10 * 1000, this, [ = ] { m_retryObtainIconTimer->start(); });
QTimer::singleShot(60 * 1000, this, &AppItem::refreshIcon);
}
update();

View File

@ -140,6 +140,9 @@ bool ThemeAppIcon::getIcon(QPixmap &pix, const QString iconName, const int size,
}
// 重新从主题中获取一次
// 如果此提交我们使用的qt版本已经包含那就可以不需要reObtain的逻辑了
// https://codereview.qt-project.org/c/qt/qtbase/+/343396
if (reObtain)
icon = getIcon(iconName);
else