Repository navigation
fix: remove AI service check from StartManager constructor - #708
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThe PR prevents deepin-editor autostart from activating the UOS AI assistant by removing eager service detection from StartManager, while retaining AI functionality through lazy initialization and retrying service detection for invalid cached states. Sequence diagram for deferred AI assistant initializationsequenceDiagram
participant StartManager
participant IflytekAiAssistant
participant DBus as com.deepin.copilot D-Bus service
participant AIFeature as AI feature
StartManager->>StartManager: constructor
Note over StartManager,DBus: No checkAiExists call during startup
AIFeature->>IflytekAiAssistant: instance()
IflytekAiAssistant->>IflytekAiAssistant: checkAiExists()
IflytekAiAssistant->>DBus: QDBusInterface construction
DBus-->>IflytekAiAssistant: service status
IflytekAiAssistant-->>AIFeature: AI functionality available
State diagram for AI service status revalidationstateDiagram-v2
[*] --> Invalid
Invalid --> Enabled: checkValid()
NotInstalled --> Enabled: checkValid()
Invalid --> NotInstalled: copilotInstalled(m_copilot)
NotInstalled --> NotInstalled: copilotInstalled(m_copilot)
Enabled --> Enabled: checkValid()
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
1. Root cause: StartManager constructor called IflytekAiAssistant::instance()->checkAiExists(), which constructs QDBusInterface and calls copilotInstalled() during startup, triggering D-Bus auto-activation of com.deepin.copilot service 2. Fix: remove checkAiExists() call from constructor; add case Invalid to checkValid() switch so copilotInstalled() runs synchronously on first AI feature invocation, transitioning m_status from Invalid to a valid state (lazy loading); remove now-unused include from startmanager.cpp 3. Impact: deepin-editor autostart no longer activates com.deepin.copilot via D-Bus at boot; AI features (TTS, STT, translation) work normally when first invoked by the user Log: Fix UOS AI window popping up when deepin-editor is set as autostart Influence: 1. Test deepin-editor autostart does not trigger UOS AI window on boot 2. Test AI features (TTS, STT, translation) work on first invocation 3. Verify no regression on normal editor startup behavior fix: 实现 checkValid 懒加载 AI 服务检测 1. 根因:StartManager 构造函数调用 IflytekAiAssistant::instance()->checkAiExists(),该方法在启动阶段 构造 QDBusInterface 并调用 copilotInstalled(),触发 D-Bus 自动 激活 com.deepin.copilot 服务 2. 方案:从构造函数移除 checkAiExists() 调用;在 checkValid() 的 switch 中增加 case Invalid 分支,首次调用 AI 功能时同步执行 copilotInstalled() 检查,将 m_status 从 Invalid 转变为有效状态 (懒加载);移除 startmanager.cpp 中已不再使用的 include 3. 影响:deepin-editor 开机自启不再通过 D-Bus 激活 com.deepin.copilot;AI 功能(TTS、STT、翻译)在用户首次使用时 正常工作 Log: 修复设置文本编辑器开机自启后 UOS AI 窗口弹出的问题 Influence: 1. 测试设置文本编辑器开机自启后,开机不再弹出 UOS AI 窗口 2. 测试在文本编辑器内首次使用 AI 功能时仍可正常工作 3. 验证编辑器正常启动行为无回归 PMS: BUG-368911
746f584 to
0eeff74
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: [] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pengfeixx 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 |
|
/merge |
|
This pr cannot be merged! (status: unknown) |
Root Cause Analysis
The
StartManagerconstructor insrc/startmanager.cppcallsIflytekAiAssistant::instance()->checkAiExists(), which triggers construction ofQDBusInterface("com.deepin.copilot", ...)during editor startup. When deepin-editor is set as autostart, this D-Bus interface construction causes the D-Bus daemon to auto-activate thecom.deepin.copilotservice (via/usr/share/dbus-1/services/com.deepin.copilot.service→Exec=/usr/bin/uos-ai-assistant), launching the UOS AI assistant process and popping up its window on boot.Key evidence:
iflytek_ai_assistant.cpp:143constructsm_copilotas aQDBusInterfacein the singleton constructor;startmanager.cpp:100callscheckAiExists()duringStartManagerinitialization. The D-Bus activation chain was confirmed by reproduction experiments observing the activation log.Fix Approach
Remove the
checkAiExists()call from theStartManagerconstructor, deferring AI service detection to first actual use of AI features (lazy loading). This eliminates the D-Bus auto-activation trigger during startup without modifying theIflytekAiAssistantclass itself.Change Safety Assessment
Code Safety
629f1617("feat: adapt new ai assistant") as a feature addition, not a bug fix — this change does not revoke any historical fix.checkAiExists()method itself is not deleted or modified; only the call site in the constructor is removed. Unit tests that directly callcheckAiExists()remain unaffected.Business Impact Scope
IflytekAiAssistant::instance()singleton is lazily created when first AI feature is invoked.com.deepin.copilotservice, preventing UOS AI window from popping up when deepin-editor is set as autostart.Verification Suggestion
Test deepin-editor autostart scenario (set as autostart, reboot) to verify UOS AI window does not appear. Then test AI features (text-to-speech, translation) to verify they still work when first invoked from within the editor.
根因分析
src/startmanager.cpp中的StartManager构造函数调用了IflytekAiAssistant::instance()->checkAiExists(),该方法在编辑器启动阶段构造QDBusInterface("com.deepin.copilot", ...)。当 deepin-editor 被设为开机自启时,该 D-Bus 接口构造导致 D-Bus 守护进程根据/usr/share/dbus-1/services/com.deepin.copilot.service(Exec=/usr/bin/uos-ai-assistant)自动激活com.deepin.copilot服务,拉起 uos-ai-assistant 进程并弹出 UOS AI 窗口。关键证据:
iflytek_ai_assistant.cpp:143在单例构造函数中构造m_copilot(QDBusInterface);startmanager.cpp:100在StartManager初始化时调用checkAiExists()。复现实验已完整观测 D-Bus 激活因果链。修复方案
从
StartManager构造函数移除checkAiExists()调用,将 AI 服务检测延迟到首次实际使用 AI 功能时执行(懒加载),不修改IflytekAiAssistant类本身。改动安全评估
代码安全评估
629f1617("feat: adapt new ai assistant")引入,属于功能引入而非 bug 修复——本次改动不撤销任何历史修复。checkAiExists()方法本身未删除或修改,仅移除构造函数中的调用点。直接调用该方法的单元测试不受影响。业务影响范围
IflytekAiAssistant::instance()单例在首次调用 AI 功能时延迟创建。com.deepin.copilot服务,避免开机自启时 UOS AI 窗口弹出。验证建议
测试设置 deepin-editor 开机自启后重启,验证 UOS AI 窗口不再弹出。然后在编辑器中首次使用 AI 功能(文本朗读、翻译),验证功能正常初始化。
PMS: BUG-368911
Summary by Sourcery
Prevent AI service activation during editor startup by removing eager initialization and deferring service checks until needed.
Bug Fixes:
Enhancements: