diff --git a/src/common/iflytek_ai_assistant.cpp b/src/common/iflytek_ai_assistant.cpp index 4f059e3a..603caf38 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 c5355b0e..4627cfdb 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);