From d69106bf3d08f659c91bbdfb943f2711625b29af Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Mon, 16 Nov 2026 22:54:10 +0800 Subject: [PATCH] fix: lazy-create copilot D-Bus interface to avoid startup auto-activation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: IflytekAiAssistant constructor created QDBusInterface for com.deepin.copilot at init, triggering D-Bus auto-activation of uos-ai-assistant when the singleton is first accessed during startup 2. Fix: move QDBusInterface creation to ensureCopilot(), called lazily from checkValid(); valid() remains read-only on m_status 3. Impact: startup path instance()->valid() no longer touches D-Bus; AI functionality unaffected—interface created on first real use 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: 延迟创建copilot D-Bus接口避免启动时自动激活 1. 根因:IflytekAiAssistant构造函数在初始化时创建QDBusInterface 指向com.deepin.copilot,单例在启动路径首次访问时触发D-Bus 自动激活uos-ai-assistant进程 2. 方案:将QDBusInterface创建移至ensureCopilot(),由checkValid() 首次使用时懒加载;valid()保持只读m_status不触发创建 3. 影响:启动路径instance()->valid()不再触碰D-Bus;AI功能不受 影响,接口在首次实际使用时创建 Log: 修复设置文本编辑器开机自启后UOS AI窗口弹出的问题 Influence: 1. 测试设置文本编辑器开机自启后,开机不再弹出UOS AI窗口 2. 测试在文本编辑器内首次使用AI功能时仍可正常工作 3. 验证编辑器正常启动行为无回归 PMS: BUG-368911 --- src/common/iflytek_ai_assistant.cpp | 12 ++++++++++-- src/common/iflytek_ai_assistant.h | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/common/iflytek_ai_assistant.cpp b/src/common/iflytek_ai_assistant.cpp index 4f059e3a2..603caf381 100644 --- a/src/common/iflytek_ai_assistant.cpp +++ b/src/common/iflytek_ai_assistant.cpp @@ -140,10 +140,17 @@ static const QString kFlytekService = "com.iflytek.aiassistant"; IflytekAiAssistant::IflytekAiAssistant(QObject *parent) : QObject(parent) - , m_copilot{new QDBusInterface(kCopilotService, kCopilotPath, kCopilotInterface)} { qCDebug(appLog) << "IflytekAiAssistant created"; - m_copilot->setTimeout(2000); +} + +QSharedPointer IflytekAiAssistant::ensureCopilot() +{ + if (!m_copilot) { + m_copilot = QSharedPointer::create(kCopilotService, kCopilotPath, kCopilotInterface); + m_copilot->setTimeout(2000); + } + return m_copilot; } bool IflytekAiAssistant::hasAudioOutputDevice() const @@ -169,6 +176,7 @@ IflytekAiAssistant *IflytekAiAssistant::instance() IflytekAiAssistant::CallStatus IflytekAiAssistant::checkValid() { qCDebug(appLog) << "checkValid status:" << m_status; + ensureCopilot(); switch (m_status) { case Invalid: case NotInstalled: diff --git a/src/common/iflytek_ai_assistant.h b/src/common/iflytek_ai_assistant.h index c5355b0ea..4627cfdbe 100644 --- a/src/common/iflytek_ai_assistant.h +++ b/src/common/iflytek_ai_assistant.h @@ -63,6 +63,8 @@ class IflytekAiAssistant : public QObject CallStatus stopTtsDirectlyInternal() const; + QSharedPointer ensureCopilot(); + static CallStatus copilotInstalled(const QSharedPointer &copilot); static CallStatus isCopilotEnabled(const QSharedPointer &copilot); static CallStatus launchCopilotChat(const QSharedPointer &copilot);