Repository navigation
fix: handle SNI NewMenu signal and empty menu path - #529
Conversation
1. Root cause: init() read m_menuPath only once without listening for NewMenu signal; race condition left it empty permanently 2. Fix: add NewMenu signal to XML and connect it to refresh m_menuPath and destroy stale importer; make menu path lazy-read in menuImporter() instead of init(); guard empty path 3. Impact: SNI tray apps now get correct right-click menu even under startup race; empty path falls back to ContextMenu(0,0) Log: Fix empty right-click menu for SNI tray apps on startup race Influence: 1. Test right-click menu for normal SNI apps after full startup 2. Test right-click menu during SNI app startup race condition 3. Test ContextMenu fallback for SNI apps without DBusMenu 4. Test menu refresh when app changes menu path at runtime fix: 修复SNI应用启动竞态时托盘右键弹空菜单 1. 根因:init() 只读取一次 m_menuPath 且未监听 NewMenu 信号, 启动竞态时读到空路径导致永久失效,无法回退 ContextMenu 2. 方案:XML 新增 NewMenu 信号声明,构造函数连接信号刷新 m_menuPath 并销毁旧 importer;menuImporter() 改为惰性读取 菜单路径并对空路径兜底返回 nullptr 3. 影响:SNI 托盘应用在启动竞态下右键菜单恢复正常;空路径 时回退 ContextMenu(0,0) 兜底 Log: 修复SNI应用启动竞态时托盘右键弹空菜单的问题 Influence: 1. 测试 SNI 应用正常启动后右键菜单功能 2. 测试 SNI 应用启动竞态时右键菜单功能 3. 测试无 DBusMenu 的 SNI 应用右键回退 ContextMenu 4. 测试应用运行中菜单路径变更后的菜单刷新 PMS: BUG-379875
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes the SNI startup race by reacting to NewMenu and deferring menu-path lookup until menu use, while preventing invalid DBusMenu importer creation so callers can fall back to ContextMenu(0,0). Sequence diagram for SNI menu refresh and fallbacksequenceDiagram
participant SNI as StatusNotifierItem
participant Handler as SniTrayProtocolHandler
participant Importer as DBusMenuImporter
participant Context as ContextMenu
SNI-->>Handler: NewMenu
Handler->>SNI: menu()
SNI-->>Handler: path()
Handler->>Handler: delete m_dbusMenuImporter
Handler->>Handler: m_dbusMenuImporter = nullptr
Handler->>Handler: menuImporter()
alt menu path is valid
Handler->>Importer: DBusMenu(m_service, m_menuPath, Handler)
Importer-->>Handler: menu importer
else menu path is empty or /NO_DBUSMENU
Handler-->>Context: ContextMenu(0, 0)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
📋 代码变更概述
根因: 修复方案:
🔍 详细分析1. 语法逻辑 ✅ (22/25 分)评价: 语法正确,逻辑清晰 ✅ 潜在问题:
涉及文件及行号:
问题分析: if (!menuImporter()) { // 第一次调用
m_sniInter->ContextMenu(0, 0);
return false;
}
auto menu = menuImporter()->menu(); // 第二次调用
menuImporter()->updateMenu(menu); // 第三次调用
menu->setFixedSize(menu->sizeHint()); // 使用 menu 指针若 建议修复: auto importer = menuImporter();
if (!importer) {
m_sniInter->ContextMenu(0, 0);
return false;
}
auto menu = importer->menu();
importer->updateMenu(menu);
menu->setFixedSize(menu->sizeHint());2. 代码质量 ✅ (23/25 分)评价: 代码结构清晰 ✅ 潜在问题:
涉及文件及行号:
建议添加注释: // 当应用菜单路径变更时,刷新 m_menuPath 并销毁旧的 importer
// 以便下次 menuImporter() 调用时创建新的 DBusMenu 实例
connect(m_sniInter, &StatusNotifierItem::NewMenu, this, [this] {
m_menuPath = m_sniInter->menu().path();
if (m_dbusMenuImporter) {
delete m_dbusMenuImporter;
m_dbusMenuImporter = nullptr;
}
});3. 代码性能 ✅ (20/20 分)评价: 性能良好,资源使用合理 ✅ 潜在问题: 无 惰性加载(lazy loading)实际上是性能改进:避免了 4. 代码安全 ✅ (30/30 分)评价: 存在0个安全漏洞 ✅
安全漏洞详情: 未发现安全漏洞 漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个 安全分析:
💡 改进建议代码示例// 1. eventFilter 中复用 importer 指针,避免 use-after-free
// 修改前:
if (!menuImporter()) {
m_sniInter->ContextMenu(0, 0);
return false;
}
auto menu = menuImporter()->menu();
menuImporter()->updateMenu(menu);
// 修改后:
auto importer = menuImporter();
if (!importer) {
m_sniInter->ContextMenu(0, 0);
return false;
}
auto menu = importer->menu();
importer->updateMenu(menu);// 2. 为 NewMenu lambda 添加注释
// 当应用菜单路径变更时,刷新 m_menuPath 并销毁旧的 importer
// 以便下次 menuImporter() 调用时创建新的 DBusMenu 实例
connect(m_sniInter, &StatusNotifierItem::NewMenu, this, [this] {
m_menuPath = m_sniInter->menu().path();
if (m_dbusMenuImporter) {
delete m_dbusMenuImporter;
m_dbusMenuImporter = nullptr;
}
});📝 审查总结本次 PR 修复了 SNI 托盘应用启动竞态时右键菜单为空的问题,修改方案合理:
主要建议:
整体代码质量良好,可以合并。 本报告由 AI 代码审查工具自动生成 |
Review 总结整体方向正确,LGTM。 核心修复( 以下是记录性说明,均不阻塞合并:
以上仅为 review 记录,不要求在本 PR 中处理。感谢修复。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BLumia, Ivy233 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 |
fix: handle SNI NewMenu signal and empty menu path
for NewMenu signal; race condition left it empty permanently
m_menuPath and destroy stale importer; make menu path lazy-read
in menuImporter() instead of init(); guard empty path
under startup race; empty path falls back to ContextMenu(0,0)
Log: Fix empty right-click menu for SNI tray apps on startup race
Influence:
fix: 修复SNI应用启动竞态时托盘右键弹空菜单
启动竞态时读到空路径导致永久失效,无法回退 ContextMenu
m_menuPath 并销毁旧 importer;menuImporter() 改为惰性读取
菜单路径并对空路径兜底返回 nullptr
时回退 ContextMenu(0,0) 兜底
Log: 修复SNI应用启动竞态时托盘右键弹空菜单的问题
Influence:
PMS: BUG-379875
Summary by Sourcery
Fix SNI tray menu initialization and refresh handling so right-click menus work across startup races and missing DBusMenu configurations.
Bug Fixes:
Enhancements: