Repository navigation
fix: activate main window on D-Bus openImageFile - #417
Conversation
Reviewer's GuideValid D-Bus image-open requests now restore, raise, and request focus for the existing main window, while preserving window state and avoiding activation for invalid requests; the implementation includes deferred minimized-window activation and focused unit/integration coverage. Sequence diagram for D-Bus image opening and main window activationsequenceDiagram
participant Caller as D-Bus caller
participant Adaptor as ApplicationAdaptor
participant FileControl
participant Window as Main window
participant QML as MainStack
Caller->>Adaptor: openImageFile(fileName)
Adaptor->>FileControl: isCanReadable(urlPath)
Adaptor->>FileControl: isImage(urlPath)
alt valid image
Adaptor->>FileControl: activateMainWindow()
alt window minimized
FileControl->>Window: setWindowStates(states without WindowMinimized)
FileControl->>Window: QTimer::singleShot(0)
QTimer->>Window: raise()
QTimer->>Window: requestActivate()
else window not minimized
FileControl->>Window: raise()
FileControl->>Window: requestActivate()
end
Adaptor-->>FileControl: openImageFile(urlPath)
FileControl-->>QML: onOpenImageFile
QML->>QML: requestSourcePath()
Adaptor-->>Caller: true
else invalid input
Adaptor-->>Caller: false
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
When the viewer is already running, the D-Bus openImageFile call only loaded the image without raising or focusing the existing window. Now the running instance activates the main window (restores it from minimized, raises, requests focus) before loading the image, so the window pops up on top and focused. 已运行实例通过 D-Bus openImageFile 打开图片时仅加载图片,不会还原、 置顶或聚焦已有窗口。现在先激活主窗口(最小化则还原,再置顶并请求 焦点)再加载图片,保证窗口置顶弹出。 Log: D-Bus 调用 openImageFile 打开图片时激活主窗口
5df491c to
1de409d
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['在 TearDown() 开头调用 stub.clear(),确保在 delete m_adaptor / m_fileControl 之前清除所有桩,避免悬空指针', '在集成测试中增加最小化窗口变体:win.setWindowStates(Qt::WindowMinimized) 后调用 openImageFile,再 processEvents() 验证延迟激活路径'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// tests/src/test_applicationadpator.cpp — 修复悬空指针风险
// 方案:在 TearDown() 开头先清除桩,再删除对象
void TearDown() override {
stub.clear(); // 先清除桩,避免删除对象时桩 lambda 解引用已销毁的栈变量
if (m_adaptor) {
delete m_adaptor;
m_adaptor = nullptr;
}
delete m_fileControl;
m_fileControl = nullptr;
}本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind 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 |
|
/forcemerge |
问题 / Problem
应用已运行时(D-Bus 服务
com.deepin.imageViewer已注册),外部通过 D-Bus 调用openImageFile打开图片:图片正常加载,但已有窗口不会还原/置顶/聚焦,窗口仍埋在后台或保持最小化。根因 / Root Cause
ApplicationAdaptor::openImageFile→Q_EMIT fileControl->openImageFile(urlPath)→MainStack.qml的Connections.onOpenImageFile仅调用requestSourcePath()加载图片,链路上无任何raise()/requestActivate()逻辑。修复 / Fix
FileControl新增activateMainWindow()(Q_INVOKABLE):遍历QGuiApplication::topLevelWindows()取可见主窗口(排除 Popup);WindowMinimized标志还原窗口(保留最大化/全屏形态),还原动作经 WM 异步完成,raise()+requestActivate()推迟到下一轮事件循环执行,避免与 WM 取消最小化/焦点重分配竞态;raise() + requestActivate()。ApplicationAdaptor::openImageFile成功分支在Q_EMIT前调用fileControl->activateMainWindow();校验不通过分支不激活。验证 / Verification
IsCheckOnly_RepeatedLockAttempts_BothSucceed失败为环境中正在运行的实例持有 single 锁文件所致,与本次改动无关):ActivateMainWindow_NoVisibleWindow_NoActionTakenActivateMainWindow_VisibleWindow_RaisesAndRequestsActivateActivateMainWindow_MinimizedWindow_RestoresKeepingOtherStatesOpenImageFile_Success_ActivatesMainWindowOpenImageFile_RejectedInput_DoesNotActivateMainWindowll-builder build构建产物替换层内二进制,测试后已恢复原文件):openImageFile,_NET_WM_STATE仍为_NET_WM_STATE_HIDDEN、_NET_ACTIVE_WINDOW为空 —— 不激活(问题复现)_NET_WM_STATE_HIDDEN清除且激活窗口 = 看图;窗口在后台 → dbus-send → 置顶并聚焦dbus-send --session --print-reply --dest=com.deepin.imageViewer / com.deepin.imageViewer.openImageFile string:"file:///tmp/dbusfix-test.png"Summary by Sourcery
Activate the existing main window when handling valid D-Bus image-open requests.
Bug Fixes:
Enhancements:
Tests: