Skip to content

fix(plugins): Update sound tray icon when audio card info changes#421

Merged
ComixHe merged 1 commit intolinuxdeepin:masterfrom
ComixHe:master
Jan 29, 2026
Merged

fix(plugins): Update sound tray icon when audio card info changes#421
ComixHe merged 1 commit intolinuxdeepin:masterfrom
ComixHe:master

Conversation

@ComixHe
Copy link
Contributor

@ComixHe ComixHe commented Jan 29, 2026

Log: Update sound tray icon when audio card info changes
Pms: BUG-349027

Summary by Sourcery

Bug Fixes:

  • Ensure the sound tray icon stays in sync when audio card information changes.

Log: Update sound tray icon when audio card info changes
Pms: BUG-349027
Signed-off-by: ComixHe <heyuming@deepin.org>
@ComixHe ComixHe requested a review from 18202781743 January 29, 2026 06:02
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 29, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Wire the sound tray view to refresh when the audio card information changes so the tray icon stays in sync with current hardware state.

Sequence diagram for updating sound tray icon on audio card info change

sequenceDiagram
    participant AudioHardware
    participant SoundModel
    participant SoundView

    AudioHardware->>SoundModel: audio card info changes
    SoundModel-->>SoundModel: updateCardsInfo()
    SoundModel-->>SoundView: cardsInfoChanged
    SoundView-->>SoundView: refresh()
    SoundView-->>SoundView: refreshIcon()
Loading

Class diagram for SoundModel and SoundView signal-slot update

classDiagram
    class SoundModel {
        +ref() SoundModel
        +volumeChanged
        +muteStateChanged
        +cardsInfoChanged
    }

    class SoundView {
        +SoundView(parent)
        +refresh()
        +refreshIcon()
    }

    SoundModel <.. SoundView : observes
    SoundModel --> SoundView : volumeChanged -> refresh
    SoundModel --> SoundView : muteStateChanged -> refresh
    SoundModel --> SoundView : cardsInfoChanged -> refresh
Loading

File-Level Changes

Change Details Files
Trigger sound tray refresh when SoundModel card info changes.
  • Add a connection from SoundModel::cardsInfoChanged to SoundView::refresh so the view updates on card info updates
  • Use a direct connection (default) for cardsInfoChanged while keeping queued connections for volume and mute changes
plugins/dde-dock/sound/soundview.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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • For consistency with the other SoundModel signal connections (which use Qt::QueuedConnection) and to avoid potential cross-thread UI updates, consider specifying a connection type for cardsInfoChanged -> refresh as well or documenting why a direct connection is safe here.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- For consistency with the other SoundModel signal connections (which use Qt::QueuedConnection) and to avoid potential cross-thread UI updates, consider specifying a connection type for cardsInfoChanged -> refresh as well or documenting why a direct connection is safe here.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

deepin pr auto review

这段代码主要是在 SoundView 的构造函数中添加了一个新的信号槽连接,用于响应声卡信息的变化。以下是对这段代码的审查意见,分为语法逻辑、代码质量、代码性能和代码安全四个方面:

1. 语法逻辑

  • 观察:代码逻辑上没有语法错误。当 SoundModel 发出 cardsInfoChanged 信号时,调用 SoundViewrefresh 槽函数,这与现有的 volumeChangedmuteStateChanged 的处理方式保持一致。
  • 建议:确认 cardsInfoChanged 信号发出的时机。如果该信号在初始化时会被频繁连续触发(例如系统正在扫描所有音频设备),可能会导致界面频繁刷新。

2. 代码质量

  • 一致性
    • 代码风格与上方保持一致,符合 Qt 编码规范。
    • 问题:上方两行连接使用了 Qt::QueuedConnection 类型,而新增的这行使用了默认连接类型(通常是 Qt::AutoConnection)。
    • 改进意见:为了保持代码的一致性和可维护性,建议明确指定连接类型。考虑到 SoundModel 可能是单例(通过 ref() 访问),且 SoundView 是 UI 组件,为了防止信号发送方和接收方在同一线程时造成重入问题或堆栈溢出(如果 refresh 内部逻辑较复杂),或者仅仅为了统一风格,建议加上 Qt::QueuedConnection
  • Lambda 表达式
    • 下方 themeTypeChanged 使用了 Lambda 表达式 [ = ]。这里按值捕获所有局部变量。虽然在此处(构造函数末尾)通常没有局部变量需要捕获,但使用 [ = ] 是一种习惯。如果不需要捕获任何变量,使用 [ ] 会更轻量且意图更明确。

3. 代码性能

  • 潜在风险cardsInfoChanged 信号可能携带大量数据(如所有声卡的详细信息),或者触发频率较高。
    • 如果 refresh() 函数执行耗时操作(如复杂的 UI 绘制或 IO 操作),频繁触发会导致界面卡顿。
    • 改进意见:检查 refresh() 函数的实现。如果 cardsInfoChanged 触发频率很高,建议在 refresh() 中加入防抖逻辑,或者确保 cardsInfoChanged 信号本身不会在短时间内连续发送多次。
  • 连接类型:使用 Qt::QueuedConnection 可以将槽函数的调用推迟到事件循环中执行,这有助于在信号密集发出时“合并”多次调用(即在一次事件循环处理中只执行最后一次),从而提升性能和响应速度。再次建议加上 Qt::QueuedConnection

4. 代码安全

  • 对象生命周期
    • SoundModel::ref() 返回的似乎是一个单例引用。在 SoundView 析构时,Qt 会自动断开与该对象的连接,因此不会出现悬空指针问题,这方面是安全的。
  • 线程安全
    • 如果 SoundModelSoundView 在同一线程,默认的 Qt::AutoConnection 是直接调用(DirectConnection)。如果 refresh 函数内部处理不当(例如删除了发送者或导致重入信号),可能会引发崩溃。使用 Qt::QueuedConnection 可以提供一定程度的隔离保护。

总结与修改建议

建议修改后的代码如下,主要增加了连接类型以保持一致性和安全性:

diff --git a/plugins/dde-dock/sound/soundview.cpp b/plugins/dde-dock/sound/soundview.cpp
index 12361d47..ea2f49b6 100644
--- a/plugins/dde-dock/sound/soundview.cpp
+++ b/plugins/dde-dock/sound/soundview.cpp
@@ -42,6 +42,7 @@ SoundView::SoundView(QWidget *parent)
 
     connect(&SoundModel::ref(), &SoundModel::volumeChanged, this, &SoundView::refresh, Qt::QueuedConnection);
     connect(&SoundModel::ref(), &SoundModel::muteStateChanged, this, &SoundView::refresh, Qt::QueuedConnection);
-    connect(&SoundModel::ref(), &SoundModel::cardsInfoChanged, this, &SoundView::refresh);
+    connect(&SoundModel::ref(), &SoundModel::cardsInfoChanged, this, &SoundView::refresh, Qt::QueuedConnection);
     connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [ = ] {
         refreshIcon();
     });

修改理由

  1. 一致性:与上方其他信号连接保持一致。
  2. 稳定性:使用 Qt::QueuedConnection 可以避免在信号连续触发时造成的堆栈溢出风险,并优化 UI 刷新性能。

@ComixHe ComixHe requested review from mhduiy and yixinshark January 29, 2026 06:03
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ComixHe, yixinshark

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

@ComixHe ComixHe merged commit c0d14cc into linuxdeepin:master Jan 29, 2026
10 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