Skip to content

Commit 4d330bf

Browse files
committed
feat: enhance notification icon handling
Updated the image processing for notification icons to avoid temporary file usage by converting images to data URL format. Added scaling for icons larger than 16x16 pixels and implemented JPEG compression to reduce memory usage. This change improves performance and reliability in displaying notification icons. Log: as title
1 parent f1ec858 commit 4d330bf

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

panels/notification/bubble/bubbleitem.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <QDBusArgument>
1111
#include <QTemporaryFile>
1212
#include <QLoggingCategory>
13+
#include <QBuffer>
1314

1415
#include <DIconTheme>
1516

@@ -141,14 +142,23 @@ static QString imagePathOfNotification(const QVariantMap &hints, const QString &
141142
img = decodeImageFromBase64(imageData);
142143
}
143144
if (!img.isNull()) {
144-
QTemporaryFile file("notification_icon");
145-
img.save(file.fileName());
146-
return file.fileName();
145+
// 通知图标通常16x16
146+
const int size = 16;
147+
if (img.width() > size || img.height() > size) {
148+
img = img.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
149+
}
150+
151+
// 将图片转换为data URL格式,避免临时文件问题
152+
QByteArray ba;
153+
QBuffer buffer(&ba);
154+
buffer.open(QIODevice::WriteOnly);
155+
// 使用JPEG格式和适当压缩率减少内存占用
156+
img.save(&buffer, "JPEG", 85);
157+
QString dataUrl = QString("data:image/jpeg;base64,%1").arg(QString::fromLatin1(ba.toBase64()));
158+
return dataUrl;
147159
}
148160

149-
DGUI_USE_NAMESPACE;
150-
auto icon = DIconTheme::findQIcon(appName, DIconTheme::findQIcon("application-x-desktop"));
151-
return icon.name();
161+
return {};
152162
}
153163

154164

0 commit comments

Comments
 (0)