Skip to content

Commit fc87106

Browse files
committed
fix: fix async access causing invalid properties in SNI tray
1. Changed StatusNotifierItem from async to sync mode to ensure properties are available when accessed 2. Implemented lazy initialization for DBusMenuImporter to avoid accessing uninitialized menu 3. Added lazy generation of tray ID to prevent empty ID when accessed before initialization 4. Stored service path separately for later use in menu importer creation 5. Fixed menu access to use lazy-loaded menu importer instead of potentially null pointer Log: Fixed system tray icons sometimes showing no menu or incorrect behavior Influence: 1. Test system tray icons from various applications (especially those using SNI protocol) 2. Verify right-click menus appear correctly for all tray icons 3. Check that tray icon IDs remain consistent and unique 4. Test theme switching while tray menus are open 5. Verify left-click activation works properly 6. Test with applications that send attention signals fix: 修复异步访问导致SNI托盘属性无效的问题 1. 将StatusNotifierItem从异步模式改为同步模式,确保访问时属性已就绪 2. 实现DBusMenuImporter的延迟初始化,避免访问未初始化的菜单 3. 添加托盘ID的延迟生成,防止在初始化前访问时返回空ID 4. 单独存储服务路径供后续创建菜单导入器使用 5. 修复菜单访问,使用延迟加载的菜单导入器代替可能为空的指针 Log: 修复系统托盘图标有时不显示菜单或行为异常的问题 Influence: 1. 测试来自不同应用程序的系统托盘图标(特别是使用SNI协议的) 2. 验证所有托盘图标的右键菜单是否正确显示 3. 检查托盘图标ID是否保持唯一且一致 4. 测试在托盘菜单打开时切换主题 5. 验证左键激活功能是否正常工作 6. 测试发送attention信号的应用程序 PMS: BUG-351643
1 parent e82424b commit fc87106

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

plugins/application-tray/sniprotocolhandler.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ SniTrayProtocolHandler::SniTrayProtocolHandler(const QString &sniServicePath, QO
104104
: AbstractTrayProtocolHandler(parent)
105105
, m_tooltip (new QLabel())
106106
, m_ignoreFirstAttention(true)
107+
, m_dbusMenuImporter(nullptr)
107108
{
108109
auto pair = serviceAndPath(sniServicePath);
110+
m_path = pair.first;
109111
// will get a unique dbus name (number like x.xxxx) and dbus path
110112
m_dbusUniqueName = pair.first.mid(1);
111113
m_sniInter = new StatusNotifierItem(pair.first, pair.second, QDBusConnection::sessionBus(), this);
112-
m_sniInter->setSync(false);
113-
m_dbusMenuImporter = new DBusMenu(pair.first, m_sniInter->menu().path(), this);
114+
m_sniInter->setSync(true);
114115
m_tooltip->setForegroundRole(QPalette::BrightText);
115-
generateId();
116116

117117
connect(m_sniInter, &StatusNotifierItem::NewIcon, this, &SniTrayProtocolHandler::iconChanged);
118118
connect(m_sniInter, &StatusNotifierItem::NewOverlayIcon, this, &SniTrayProtocolHandler::overlayIconChanged);
@@ -130,7 +130,7 @@ SniTrayProtocolHandler::SniTrayProtocolHandler(const QString &sniServicePath, QO
130130
connect(m_sniInter, &StatusNotifierItem::NewToolTip, this, &SniTrayProtocolHandler::tooltiChanged);
131131
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [this](DGuiApplicationHelper::ColorType themeType) {
132132
Q_UNUSED(themeType)
133-
m_dbusMenuImporter->updateMenu(true);
133+
menuImporter()->updateMenu(true);
134134
});
135135
}
136136

@@ -145,13 +145,25 @@ void SniTrayProtocolHandler::generateId()
145145
m_id = UTIL->generateUniqueId(id);
146146
}
147147

148+
DBusMenuImporter *SniTrayProtocolHandler::menuImporter() const
149+
{
150+
if (!m_dbusMenuImporter) {
151+
auto that = const_cast<SniTrayProtocolHandler *>(this);
152+
that->m_dbusMenuImporter = new DBusMenu(m_path, m_sniInter->menu().path(), that);
153+
}
154+
return m_dbusMenuImporter;
155+
}
156+
148157
uint32_t SniTrayProtocolHandler::windowId() const
149158
{
150159
return m_sniInter->windowId();
151160
}
152161

153162
QString SniTrayProtocolHandler::id() const
154163
{
164+
if (m_id.isEmpty()) {
165+
const_cast<SniTrayProtocolHandler *>(this)->generateId();
166+
}
155167
return m_id;
156168
}
157169

@@ -238,7 +250,7 @@ bool SniTrayProtocolHandler::eventFilter(QObject *watched, QEvent *event)
238250
if (mouseEvent->button() == Qt::LeftButton) {
239251
m_sniInter->Activate(0, 0);
240252
} else if (mouseEvent->button() == Qt::RightButton) {
241-
auto menu = m_dbusMenuImporter->menu();
253+
auto menu = menuImporter()->menu();
242254
Q_CHECK_PTR(menu);
243255
if (menu->isEmpty()) {
244256
m_sniInter->ContextMenu(0, 0);

plugins/application-tray/sniprotocolhandler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ class SniTrayProtocolHandler : public AbstractTrayProtocolHandler
7474

7575
private:
7676
void generateId();
77+
DBusMenuImporter *menuImporter();
7778

7879
private:
7980
QString m_dbusUniqueName;
8081
QLabel *m_tooltip;
8182
StatusNotifierItem *m_sniInter;
8283
DBusMenuImporter *m_dbusMenuImporter;
8384
QString m_id;
85+
QString m_path;
8486
bool m_ignoreFirstAttention;
8587
};
8688
}

0 commit comments

Comments
 (0)