Skip to content

fix(power): play low battery sound via SoundEffect1 DBus service - #206

Merged
deepin-bot[bot] merged 1 commit into
masterfrom
agent/developer/f78c5154910e
Nov 3, 2026
Merged

deepin-bot[bot] merged 1 commit into
masterfrom
agent/developer/f78c5154910e

Conversation

@52cyb

@52cyb 52cyb commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

修复说明

低电量音效未通过 SoundEffect1 DBus 服务播放,LowPowerManager::playBatterySound() 直接调用 paplay 硬编码路径,绕过了音效开关检查和声音主题查找。

修复后统一通过 SoundEffect1 DBus 服务播放,与插拔电源、休眠恢复音效逻辑一致。

变更内容

  1. 新建 soundeffectutil.h — header-only 工具函数,在 SoundEffect 命名空间下通过 SoundEffect1 DBus 服务播放音效
  2. 修改 lowpowermanager.cpp — playBatterySound() 从 paplay 改为 SoundEffect::playSystemSound("power-unplug-battery-low")
  3. 修改 powermanager.cpp — 删除文件级 static playSystemSound(),改用 SoundEffect::playSystemSound()
  4. 修改 CMakeLists.txt — 将 soundeffectutil.h 加入 _src_headers

关联

Summary by Sourcery

Use the SoundEffect1 DBus service for all power and low-battery sounds instead of directly invoking a fixed audio player.

Bug Fixes:

  • Route low-battery notifications through the SoundEffect1 DBus service so sound settings and theme-specific audio are respected.

Enhancements:

  • Centralize system sound playback for power-related events in a shared SoundEffect utility.

Build:

  • Include the new sound effect utility header in the session build sources.

@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Routes all power-related sounds, including low-battery alerts, through a shared SoundEffect1 DBus utility, allowing the service to apply sound settings and theme resolution consistently while removing duplicated playback code.

Sequence diagram for unified power sound playback

sequenceDiagram
    participant LowPowerManager
    participant PowerManager
    participant SoundEffect
    participant SoundEffect1DBus

    LowPowerManager->>SoundEffect: playSystemSound(power-unplug-battery-low)
    PowerManager->>SoundEffect: playSystemSound(power-unplug or power-plug)
    PowerManager->>SoundEffect: playSystemSound(suspend-resume)
    SoundEffect->>SoundEffect1DBus: PlaySound(soundEvent)
    SoundEffect1DBus-->>SoundEffect: Apply sound settings and theme resolution
Loading

File-Level Changes

Change Details Files
Centralize power-management sound playback through a shared SoundEffect1 DBus helper.
  • Added a header-only utility that asynchronously invokes the SoundEffect1 PlaySound method on the session bus.
  • Replaced the low-battery paplay invocation with the power-unplug-battery-low sound event.
  • Updated power plug/unplug and suspend/resume playback to use the shared utility.
  • Removed the duplicated local DBus playback helper.
  • Registered the new header with the session build sources.
src/plugin-qt/power/session/soundeffectutil.h
src/plugin-qt/power/session/lowpowermanager.cpp
src/plugin-qt/power/session/powermanager.cpp
src/plugin-qt/power/session/CMakeLists.txt

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

@52cyb
52cyb force-pushed the agent/developer/f78c5154910e branch from 2363993 to 637f962 Compare October 27, 2026 12:32
@52cyb
52cyb marked this pull request as ready for review October 27, 2026 12:36

@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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@deepin-bot

deepin-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.48
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #208

@deepin-bot

deepin-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.49
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #210

@deepin-bot

deepin-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.50
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #213

@52cyb
52cyb force-pushed the agent/developer/f78c5154910e branch 2 times, most recently from f4acdf9 to 96f9a54 Compare November 3, 2026 02:29
LowPowerManager::playBatterySound() was calling paplay with a hardcoded
audio file path, bypassing the SoundEffect1 DBus service. This meant the
sound effect toggle and sound theme lookup were skipped entirely.

Extract the SoundEffect1 DBus call into a shared header-only utility
(SoundEffect::playSystemSound) and use it in both LowPowerManager and
PowerManager, making the low battery sound consistent with plug/unplug
and suspend-resume sound behavior.

PMS bug: https://pms.uniontech.com/bug-view-380987.html
@52cyb
52cyb force-pushed the agent/developer/f78c5154910e branch from 96f9a54 to 85f327e Compare November 3, 2026 02:39
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交将低电量提示音播放方式从 QProcess 启动外部进程 paplay 改为通过 SoundEffect1 DBus 服务播放, 同时将 powermanager.cpp 中已有的 playSystemSound 静态函数提取为公共头文件 soundeffectutil.h, 消除了重复代码,统一了声音播放接口。代码语法正确、逻辑清晰,重构合理,性能有所提升(避免进程创建开销), 无安全漏洞。OCR 指出 asyncCall 返回值未检查、失败时无日志输出,属低级别可维护性建议,不影响通过。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无语法逻辑问题,代码可正常编译']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['建议在 soundeffectutil.h 中使用 QDBusPendingCallWatcher 监听异步调用结果, 在失败时输出 qWarning 日志,便于问题排查。示例: QDBusPendingCall call = QDBusConnection::sessionBus().asyncCall(msg); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call); QObject::connect(watcher, &QDBusPendingCallWatcher::finished, [](QDBusPendingCallWatcher *w) {\n QDBusPendingReply reply = *w;\n if (reply.isError())\n qWarning() << "Failed to play system sound:" << reply.error().message();\n w->deleteLater();\n});']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无性能问题,重构后性能有所提升']


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: ['无安全问题']


💡 改进建议代码示例

// soundeffectutil.h - 建议增加错误日志的可选改进版本
#ifndef SOUNDEFFECTUTIL_H
#define SOUNDEFFECTUTIL_H

#include <QString>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QDBusPendingCall>
#include <QDBusPendingCallWatcher>
#include <QDBusPendingReply>
#include <QDebug>

namespace SoundEffect {

inline void playSystemSound(const QString &soundEvent)
{
    QDBusMessage msg = QDBusMessage::createMethodCall(
        QStringLiteral("org.deepin.dde.SoundEffect1"),
        QStringLiteral("/org/deepin/dde/SoundEffect1"),
        QStringLiteral("org.deepin.dde.SoundEffect1"),
        QStringLiteral("PlaySound"));
    msg << soundEvent;
    QDBusPendingCall call = QDBusConnection::sessionBus().asyncCall(msg);
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call);
    QObject::connect(watcher, &QDBusPendingCallWatcher::finished, [](QDBusPendingCallWatcher *w) {
        QDBusPendingReply<void> reply = *w;
        if (reply.isError())
            qWarning() << "Failed to play system sound:" << reply.error().message();
        w->deleteLater();
    });
}

} // namespace SoundEffect

#endif // SOUNDEFFECTUTIL_H

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 52cyb, mhduiy

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

@52cyb

52cyb commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit fc30590 into master Nov 3, 2026
7 of 8 checks passed
@52cyb
52cyb deleted the agent/developer/f78c5154910e branch November 3, 2026 03:25
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