Skip to content

Conversation

@qxp930712
Copy link

@qxp930712 qxp930712 commented Feb 4, 2026

Updated the logic in the AudioApplet to correctly identify and
display the mute icon when the volume level is less than or
equal to 1.

Previously, the code failed to explicitly handle the state where
volume was 0 or very low, potentially resulting in incorrect
icon rendering or undefined behavior. The change adds an else
block to return "osd_volume_mute" in these cases, ensuring
accurate UI feedback for users.

Log: Fixed the audio OSD mute icon display for silent state

Influence:
1. Test volume at 0% to ensure the mute icon is displayed
2. Test volume between 1% and 66% to ensure the low/mid volume icon is displayed
3. Test volume above 66% to ensure the high volume icon is displayed
4. Verify icon switching behavior when sliding the volume slider

pms: BUG-349767

Summary by Sourcery

Bug Fixes:

  • Ensure the mute icon is shown when the audio volume is at or near zero by defaulting the volume level state to mute.

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 4, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts AudioApplet volume icon selection so that silent or near-silent audio correctly uses the mute icon and non-zero volumes map to the appropriate volume levels.

Flow diagram for AudioApplet volume icon selection logic

graph TD
  A["Start: fetchIconName"] --> B["Read m_volumeValue into volume"]
  B --> C{Is volume > 0?}
  C -- "No" --> D["Set level to mute"]
  C -- "Yes" --> E{Is volume <= 0.33?}
  E -- "Yes" --> F["Set level to 33"]
  E -- "No" --> G{Is volume <= 0.66?}
  G -- "Yes" --> H["Set level to 66"]
  G -- "No" --> I["Set level to 100"]
  D --> J["Return icon name based on level"]
  F --> J
  H --> J
  I --> J
  J --> K["End: icon rendered in OSD"]
Loading

File-Level Changes

Change Details Files
Update default audio volume icon level to represent mute state when no volume thresholds are met.
  • Change the initial volume level indicator from a numeric string to a mute state label
  • Retain existing conditional thresholds for low and medium volume based on the numeric volume value
panels/notification/osd/audio/audioapplet.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:

  • Consider making the mute case explicit (e.g., if (volume <= 0.0) level = "mute";) rather than relying on the default initialization, which will improve readability and reduce the chance of regressions if the logic is reordered later.
  • Double-check that "mute" is a valid level string for all icon name compositions that use level (e.g., osd_volume_<level>); if some paths assume numeric levels, it might be safer to special-case the mute icon name instead of changing the default level.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider making the mute case explicit (e.g., `if (volume <= 0.0) level = "mute";`) rather than relying on the default initialization, which will improve readability and reduce the chance of regressions if the logic is reordered later.
- Double-check that `"mute"` is a valid level string for all icon name compositions that use `level` (e.g., `osd_volume_<level>`); if some paths assume numeric levels, it might be safer to special-case the mute icon name instead of changing the default level.

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

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, qxp930712

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

    Updated the logic in the AudioApplet to correctly identify and
    display the mute icon when the volume level is less than or
    equal to 1.

    Previously, the code failed to explicitly handle the state where
    volume was 0 or very low, potentially resulting in incorrect
    icon rendering or undefined behavior. The change adds an else
    block to return "osd_volume_mute" in these cases, ensuring
    accurate UI feedback for users.

    Log: Fixed the audio OSD mute icon display for silent state

    Influence:
    1. Test volume at 0% to ensure the mute icon is displayed
    2. Test volume between 1% and 66% to ensure the low/mid volume icon
    is displayed
    3. Test volume above 66% to ensure the high volume icon is displayed
    4. Verify icon switching behavior when sliding the volume slider

    pms: BUG-349767
@18202781743
Copy link
Contributor

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Feb 4, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 7ce650f into linuxdeepin:master Feb 4, 2026
7 of 11 checks passed
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码的修改将音量图标的默认状态从字符串 "0" 改为 "mute"。以下是对这段代码的详细审查和改进建议:

1. 语法逻辑

  • 当前逻辑:代码将 level 初始化为 "mute",随后通过 if-else 结构根据 volume 的数值更新 level
  • 潜在逻辑漏洞
    • 如果 volume 为 0,代码会跳过 ifelse if 块,level 保持为 "mute"。这符合预期(静音状态)。
    • 边界问题:如果 volume 大于 0.66,代码没有对应的 else 分支。此时 level 仍然保持初始值 "mute",或者如果之前的逻辑有 else(diff 未显示完整),可能会是其他值。但根据现有 diff,如果音量 > 0.66,结果将是 "mute",这显然是错误的,应该显示为高音量(例如 "100")。
  • 改进建议:必须添加 else 分支来处理音量大于 0.66 的情况。

2. 代码质量

  • 硬编码字符串"mute", "33", "66" 等作为魔法字符串直接写在代码中,降低了可维护性。
  • 浮点数比较:直接比较浮点数(如 0.33)在某些情况下可能存在精度问题,虽然在这个 UI 显示场景下通常可以接受,但最好明确范围。
  • 改进建议
    • 使用 enumstatic const QString 定义这些状态常量。
    • 考虑将阈值定义为常量,例如 const double kLowVolumeThreshold = 0.33;

3. 代码性能

  • 性能影响:此代码段涉及简单的浮点数比较和字符串赋值,性能开销极小,通常不需要优化。
  • 微小优化QString 的赋值涉及内存分配(虽然小字符串可能有优化),但在这种调用频率不高的 UI 回调函数中,这完全不是瓶颈。

4. 代码安全

  • 类型安全m_volumeValue 被读取为 double,确保其来源可靠,防止非数值输入导致逻辑错误。
  • 改进建议:如果 m_volumeValue 可能来自外部不可信输入,建议在函数入口处添加范围检查(例如 std::clampif 判断),确保其在 [0.0, 1.0] 之间。

5. 综合改进代码示例

基于以上分析,建议重构代码如下:

// 建议在类定义中或匿名命名空间中定义常量
namespace {
    const QString kLevelMute = "mute";
    const QString kLevelLow  = "33";
    const QString kLevelMid  = "66";
    const QString kLevelHigh = "100";
    
    const double kLowThreshold  = 0.33;
    const double kHighThreshold = 0.66;
}

QString AudioApplet::fetchIconName() const
{
    // 确保音量值在合法范围内,防止越界
    const double volume = qBound(0.0, m_volumeValue, 1.0);

    QString level;
    if (volume <= 0.0) {
        level = kLevelMute;
    } else if (volume <= kLowThreshold) {
        level = kLevelLow;
    } else if (volume <= kHighThreshold) {
        level = kLevelMid;
    } else {
        level = kLevelHigh;
    }
    
    // ... 后续拼接图标名称的逻辑
}

总结

原代码修改将默认状态改为 "mute" 是合理的,但缺少对高音量(> 0.66)的处理分支是一个严重的逻辑 Bug。建议补充完整的 if-else 逻辑,并使用常量替代魔法字符串以提高代码质量。

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.

4 participants