Skip to content

Conversation

@fly602
Copy link
Contributor

@fly602 fly602 commented Nov 6, 2025

Summary by Sourcery

Simplify audio configuration, refactor module unloading, improve BlueZ port priority handling, streamline gesture action invocation, remove legacy files, and update dependencies.

Enhancements:

  • Simplify audio config saving by removing legacy profile and port persistence and retaining only saveAudioState
  • Unload PulseAudio modules via context.UnloadModule instead of exec.Command calls
  • Refactor BlueZ port priority logic by detecting profile names through portBluezMode
  • Replace gesture builtinSets mapping with a doActionByName lookup and update edge gesture action to ShowMultiTask

Build:

  • Bump github.com/linuxdeepin/go-dbus-factory and github.com/linuxdeepin/go-lib versions

Chores:

  • Remove obsolete audio1/config.go, config_test.go, and audio shell scripts

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 6, 2025

Reviewer's Guide

This PR refactors audio configuration and module management by removing legacy file-based settings, replacing pactl exec invocations with direct context API calls for module loading/unloading, streamlines Bluetooth port priority logic, simplifies gesture action dispatch, and updates module dependencies.

Sequence diagram for direct module unload via context API (unsetMono/unsetReduceNoise)

sequenceDiagram
participant Audio
participant Context
Audio->>Context: UnloadModuleByName("module-remap-sink")
Audio->>Context: UnloadModuleByName("module-echo-cancel")
Audio->>Context: UnloadModule(module.Index)
Loading

Sequence diagram for gesture action dispatch via doActionByName

sequenceDiagram
participant Manager
participant doActionByName
participant actionInfo
Manager->>doActionByName: Call with action name
loop For each action in actions
  doActionByName->>actionInfo: If action.Name matches, call fn()
end
Loading

Class diagram for refactored Audio module management

classDiagram
class Audio {
  +saveConfig()
  +doSaveConfig()
  +unsetMono()
  +setMono(enable bool)
  +unsetReduceNoise()
  +hasReduceNoise(source string)
  -saveAudioState()
}
class Sink {
  +SetVolume(value float64, isPlay bool)
  +SetMono(enable bool)
  -audio: Audio
}
Audio <|-- Sink
Audio : context()
Audio : getDefaultSinkName()
Audio : getDefaultSourceName()
Audio : saveAudioState()
Audio : unsetMono()
Audio : unsetReduceNoise()
Audio : hasReduceNoise(source string)
Sink : SetMono(enable bool)
Sink : audio
Sink : SetVolume(value float64, isPlay bool)
Loading

Class diagram for updated Card port priority logic

classDiagram
class Card {
  +update(card *pulse.Card)
  +sortPortsByPriority(card *pulse.Card)
}
class pulse.CardPortInfo {
  +Name string
  +Profiles []Profile
  +Priority int
  +Available int
}
Card : update(card *pulse.Card)
Card : sortPortsByPriority(card *pulse.Card)
Card --> pulse.CardPortInfo : uses
class Profile {
  +Name string
  +Available int
}
Profile <|-- pulse.CardPortInfo : part of
Card : portBluezMode(port *pulse.CardPortInfo) string
Loading

Class diagram for simplified gesture action dispatch

classDiagram
class Manager {
  +Exec(evInfo EventInfo) error
  +GetInterfaceName() string
  -gesture gesture.Gesture
  -dock dock.Dock
  -display display.Display
}
class actionInfo {
  +Name string
  +fn func() error
}
Manager : Exec(evInfo EventInfo) error
Manager : GetInterfaceName() string
Manager : doToggleNotifications() error
Manager : doActionByName(name string) error
Manager --> actionInfo : uses
Loading

File-Level Changes

Change Details Files
Consolidate audio config saving logic
  • Removed legacy config struct and serialization loops
  • Eliminated readConfig/saveConfig branches based on SourcePort
  • Simplified doSaveConfig to invoke saveAudioState directly
audio1/audio_config.go
Replace pactl exec calls with context API for module management
  • Removed os/exec import and direct pactl unload-module commands
  • Added Audio.unsetMono and updated Sink.SetMono to use it
  • Changed reduce noise unload logic to use context.UnloadModule
  • Updated hasReduceNoise to call context.UnloadModule with module index
audio1/audio.go
audio1/sink.go
Refactor Bluetooth port priority determination
  • Introduced portBluezMode helper to extract mode from port profiles
  • Replaced switch on port.Name with mode-based priority assignment
  • Adjusted priority constants in bluez_audio.go
audio1/card.go
audio1/bluez_audio.go
Simplify gesture action dispatch
  • Removed builtinSets map and handleBuiltinAction method
  • Updated Exec logic to call doActionByName for built-in actions
  • Added doActionByName helper in gesture_action.go
gesture1/manager.go
gesture1/gesture_action.go
Upgrade dependency versions
  • Bumped github.com/linuxdeepin/go-dbus-factory
  • Bumped github.com/linuxdeepin/go-lib
go.mod

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 there - I've reviewed your changes and they look great!


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.

The changes address Bluetooth audio port priority issues by improving
the priority assignment logic. Previously, port priorities were
hardcoded based on port names, which was unreliable. Now priorities are
determined by analyzing the port's profile information to accurately
identify the audio mode (A2DP, headset, or handsfree). Additionally,
the audio configuration system has been simplified by removing unused
configuration file handling code and the first-run initialization logic
since these features are no longer needed.

Log: Fixed Bluetooth audio port priority assignment to correctly
identify audio modes

Influence:
1. Test Bluetooth audio device connection and automatic profile
selection
2. Verify A2DP mode has higher priority than headset mode
3. Check that audio switches correctly between different Bluetooth
profiles
4. Test audio output quality in different Bluetooth modes
5. Verify mono audio settings work properly with Bluetooth devices

fix: 修复蓝牙音频端口优先级分配问题

本次修改解决了蓝牙音频端口优先级问题,改进了优先级分配逻辑。之前基于端口
名称硬编码优先级的方式不可靠,现在通过分析端口的配置文件信息来准确识别音
频模式(A2DP、耳机或免提)。此外,简化了音频配置系统,移除了未使用的配置
文件处理代码和首次运行初始化逻辑,因为这些功能不再需要。

Log: 修复蓝牙音频端口优先级分配,正确识别音频模式

Influence:
1. 测试蓝牙音频设备连接和自动配置文件选择
2. 验证A2DP模式优先级高于耳机模式
3. 检查音频在不同蓝牙配置文件之间正确切换
4. 测试不同蓝牙模式下的音频输出质量
5. 验证单声道设置与蓝牙设备正常工作
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码进行审查和分析:

  1. 代码逻辑变更分析:
  • 移除了首次运行时的配置清理逻辑(audio.go中的firstRun相关代码)
  • 删除了配置文件相关的实现(config.go和config_test.go被完全删除)
  • 简化了配置保存逻辑(audio_config.go中的doSaveConfig函数)
  • 修改了蓝牙音频设备的优先级设置(bluez_audio.go)
  • 优化了端口优先级的判断逻辑(card.go)
  • 简化了单声道设置的逻辑(sink.go)
  1. 代码质量改进建议:

a) audio.go中的变更:

  • 移除firstRun相关代码是合理的,因为这个功能可能会导致用户配置意外丢失
  • 建议在移除这类功能时,应该添加适当的迁移机制,确保重要配置不会丢失

b) audio_config.go中的变更:

  • doSaveConfig函数被大幅简化,现在只保存音频状态
  • 建议添加注释说明为什么移除了其他配置的保存逻辑
  • 错误处理可以更详细,比如记录具体失败原因

c) bluez_audio.go中的变更:

  • 优先级设置更加合理,A2DP优先级最高(20000)
  • 建议添加注释说明不同优先级的用途和选择依据

d) card.go中的变更:

  • 新增的portBluezMode函数使用了字符串匹配来判断模式,这种方式可能不够健壮
  • 建议使用更严格的模式判断,比如预定义的模式列表
  • 日志级别使用Warning可能过于频繁,建议改为Debug
  1. 性能优化建议:
  • card.go中的portBluezMode函数使用了strings.Contains,这在大量端口时可能影响性能
  • 建议使用预编译的正则表达式或更高效的字符串匹配方法
  1. 安全性建议:
  • 配置文件的移除需要谨慎,建议在删除前进行备份
  • 字符串匹配逻辑应该考虑大小写敏感性的统一处理
  1. 其他建议:
  • 移除的配置相关功能可能会影响用户体验,建议添加迁移指南
  • 代码变更较大,建议更新相关文档
  • 建议添加单元测试覆盖新的逻辑

这些变更总体上简化了代码结构,但需要注意对现有功能的影响,特别是配置相关的变更。建议在部署前进行充分的测试。

@fly602 fly602 changed the title Fix 339685 fix: fix bluetooth audio port priority assignment Nov 6, 2025
@fly602 fly602 merged commit 49cd293 into linuxdeepin:master Nov 6, 2025
14 of 17 checks passed
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, 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

@fly602 fly602 deleted the fix-339685 branch November 7, 2025 03:12
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