Skip to content

fix(editor): disable voice reading when TTS service is unavailable - #497

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
tianming-1996:feature/fix-BUG372251
Jul 30, 2026
Merged

fix(editor): disable voice reading when TTS service is unavailable#497
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
tianming-1996:feature/fix-BUG372251

Conversation

@tianming-1996

@tianming-1996 tianming-1996 commented Jul 30, 2026

Copy link
Copy Markdown

Bug

https://pms.uniontech.com/bug-view-372251.html

问题现象

杀掉 uos-ai 进程后,文本编辑器未选中文字时右键菜单"语音朗读"未置灰,仍可点击。

根因

TextEdit::popRightMenu() 中,当 DBus 调用 com.iflytek.aiassistantgetTTSEnable 失败时(uos-ai 进程被杀,服务消失),错误处理分支直接 m_voiceReadingAction->setEnabled(true),跳过了文字选中状态检查,导致"语音朗读"菜单项在未选中文字时仍可点击。

正常路径会检查 textCursor().hasSelection() && voiceReadingState,但 DBus 失败分支和无音频设备分支均无条件 setEnabled(true),逻辑不一致。

修复

将 DBus 失败分支和无音频设备分支的 setEnabled(true) 改为 setEnabled(false):服务不可用或无音频设备时,"语音朗读"功能无法工作,菜单项应置灰。

src/editor/dtextedit.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

Summary by Sourcery

Bug Fixes:

  • Disable the 'voice reading' context menu action when DBus TTS checks fail or no audio output device is detected, preventing it from being clickable in unsupported states.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @tianming-1996, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the text editor’s context menu logic so that the 'voice reading' action is disabled when the TTS service or audio output device is unavailable, fixing inconsistent enablement behavior when uos-ai is killed or no audio device is detected.

File-Level Changes

Change Details Files
Align voice reading menu enablement with TTS service and audio device availability to prevent unusable actions from being clickable.
  • Change DBus failure branch for getTTSEnable to disable the voice reading action instead of enabling it.
  • Change the no-audio-output-device branch to disable the voice reading action instead of enabling it.
  • Preserve existing selection-based enablement logic for the normal path while making error paths consistent with actual capability.
src/editor/dtextedit.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

The "Text to Speech" right-click menu item enablement logic had a
mismatch between the normal path and the error-handling paths in
TextEdit::popRightMenu(). The normal path checks hasSelection(), but
both the DBus-failure branch and the no-audio-device branch bypassed
this check, unconditionally calling setEnabled(true) — so the menu
stayed enabled even with no text selected.

The fix preserves the text-selection check in the error branches:
when DBus fails or no audio device is present, the action is only
enabled if the user has actually selected text (or has a column
selection). slotVoiceReadingAction() already handles the unavailable
service gracefully with a user-facing message.

Log: 修复杀掉uos ai进程后,未选中文字时右键菜单"语音朗读"未置灰的问题
Bug: https://pms.uniontech.com/bug-view-372251.html
@tianming-1996
tianming-1996 force-pushed the feature/fix-BUG372251 branch from 806d54b to d2f1d65 Compare July 30, 2026 12:18
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修复了语音朗读按钮在异常情况下强制可用的问题,逻辑合理且无安全风险
修复了原有的状态判断缺陷,提升了用户体验和代码健壮性

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

修改位于 src/editor/dtextedit.cpp 的 TextEdit::popRightMenu 函数中,将异常分支下的按钮状态从强制启用改为根据选中文本或列选状态判断,逻辑正确无误。
潜在问题:无
建议:无

  • 2.代码质量(良好)✓

代码修改简洁明了,直接复用了现有的状态判断条件,符合代码规范,消除了原先可能导致无效操作的隐患。
潜在问题:无
建议:无

  • 3.代码性能(无性能问题)✓

仅涉及简单的布尔逻辑判断和 UI 状态更新,不会产生性能瓶颈。
潜在问题:无
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次修改仅涉及 UI 控件状态控制,无外部输入处理或系统命令调用,不存在安全风险。

  • 建议:无需额外安全修复

■ 【改进建议代码示例】

-            m_voiceReadingAction->setEnabled(true);
+            m_voiceReadingAction->setEnabled(textCursor().hasSelection() || m_hasColumnSelection);

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: max-lvs, tianming-1996

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tianming-1996

Copy link
Copy Markdown
Author

/merge

@deepin-bot
deepin-bot Bot merged commit f015697 into linuxdeepin:release/eagle Jul 30, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants