Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fly602 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideAdjusts audio port priority behavior so that user-selected ports move to the front of their type queue, introduces per-card default input/output ports in config, refactors priority iteration to no longer depend on dynamic availability lists, and adds logic to sort/rearrange card ports based on priority and stored defaults while cleaning up removed ports. Sequence diagram for setting default audio port prioritysequenceDiagram
actor User
participant Audio
participant PriorityManager
participant PriorityPolicy
participant ConfigKeeper
User->>Audio: selectPort(cardName, portName, direction)
Audio->>PriorityManager: SetTheFirstPort(cardName, portName, direction)
alt direction is sink
PriorityManager->>PriorityPolicy: Output.SetTheFirstPort(cardName, portName)
else direction is source
PriorityManager->>PriorityPolicy: Input.SetTheFirstPort(cardName, portName)
end
PriorityPolicy->>PriorityPolicy: FindPort(cardName, portName)
PriorityPolicy-->>PriorityManager: bool success
alt port found
PriorityPolicy->>PriorityPolicy: reorder Types and Ports
PriorityManager->>ConfigKeeper: SetDefaultPort(cardName, portName, direction)
ConfigKeeper->>ConfigKeeper: update CardConfig.DefaultOutputPort or DefaultInputPort
ConfigKeeper->>ConfigKeeper: Save()
PriorityManager->>PriorityManager: Print()
PriorityManager->>PriorityManager: Save()
else port not found
PriorityPolicy-->>PriorityManager: false
end
Updated class diagram for audio priority and config modelsclassDiagram
class PriorityManager {
-string file
+PriorityPolicy Output
+PriorityPolicy Input
+NewPriorityManager(path string) PriorityManager
+Init(cards CardList) void
+refreshPorts(cards CardList) void
+removeNonExistentPorts(policy PriorityPolicy, currentPorts map[string]map[string]bool) void
+arrangeCardPorts(card Card) void
+moveCardPortToFirst(ports pulse.CardPortInfos, portName string) void
+GetTheFirstPort(direction int) PriorityPort, Position
+SetTheFirstPort(cardName string, portName string, direction int) void
+LoopAvaiablePort(direction int, pos Position) PriorityPort, Position
+Print() void
+Save() void
}
class PriorityPolicy {
+map[int][]PriorityPort Ports
+PriorityTypeList Types
+InsertPort(card pulse.Card, port pulse.CardPortInfo) void
+insertByPriority(newPort PriorityPort, tp int) void
+GetTheFirstPort() PriorityPort, Position
+GetNextPort(pos Position) PriorityPort, Position
+SetTheFirstPort(cardName string, portName string) bool
+FindPort(cardName string, portName string) Position
}
class PriorityPort {
+string CardName
+string PortName
+int PortType
+uint32 Priority
}
class Position {
+int tp
+int index
}
class ConfigKeeper {
-sync.Mutex mu
+map[string]*CardConfig Cards
+SetMuteAll(mute bool) void
+SetDefaultPort(cardName string, portName string, direction int) void
+GetDefaultPort(cardName string, direction int) string
+Save() void
}
class CardConfig {
+string Name
+map[string]*PortConfig Ports
+string DefaultOutputPort
+string DefaultInputPort
+UpdatePortConfig(portConfig PortConfig) void
}
class Card {
+pulse.Card core
+pulse.CardPortInfos Ports
+update(card pulse.Card) void
}
class pulse.Card
class pulse.CardPortInfo {
+string Name
+int Direction
+uint32 Priority
+int Available
}
class GetConfigKeeper
PriorityManager --> PriorityPolicy : Output
PriorityManager --> PriorityPolicy : Input
PriorityManager --> Card : uses in refreshPorts
PriorityManager --> ConfigKeeper : uses via GetConfigKeeper
PriorityPolicy --> PriorityPort : manages
PriorityPolicy --> Position : returns
PriorityPolicy --> pulse.Card : uses
PriorityPolicy --> pulse.CardPortInfo : uses
ConfigKeeper --> CardConfig : owns
Card --> pulse.Card : wraps
Card --> pulse.CardPortInfo : Ports
GetConfigKeeper --> ConfigKeeper : returns
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- ConfigKeeper.SetDefaultPort returns early if the card config does not already exist, which means the first manual selection for a new card will be silently ignored; consider creating a CardConfig on demand (mirroring NewCardConfig) instead of just logging a warning.
- GetTheFirstPort/GetNextPort in PriorityPolicy no longer take availability into account and instead rely on refreshPorts filtering; if port availability can change without a full refresh, you may want to keep a lightweight availability check here or ensure refreshPorts is always triggered on availability events.
- InsertPort now always prepends the port and no longer uses insertByPriority, but insertByPriority is still present; consider either removing insertByPriority or documenting clearly why it remains unused to avoid confusion about which priority mechanism is authoritative.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- ConfigKeeper.SetDefaultPort returns early if the card config does not already exist, which means the first manual selection for a new card will be silently ignored; consider creating a CardConfig on demand (mirroring NewCardConfig) instead of just logging a warning.
- GetTheFirstPort/GetNextPort in PriorityPolicy no longer take availability into account and instead rely on refreshPorts filtering; if port availability can change without a full refresh, you may want to keep a lightweight availability check here or ensure refreshPorts is always triggered on availability events.
- InsertPort now always prepends the port and no longer uses insertByPriority, but insertByPriority is still present; consider either removing insertByPriority or documenting clearly why it remains unused to avoid confusion about which priority mechanism is authoritative.
## Individual Comments
### Comment 1
<location path="audio1/priority_policy.go" line_range="242-246" />
<code_context>
}
-func (pp *PriorityPolicy) GetNextPort(available portList, pos *Position) (*PriorityPort, *Position) {
+func (pp *PriorityPolicy) GetNextPort(pos *Position) (*PriorityPort, *Position) {
if pos.tp == PortTypeInvalid {
return nil, &Position{tp: PortTypeInvalid, index: -1}
}
for tp := pos.tp; tp < PortTypeCount; tp++ {
- for i := pos.index + 1; i < len(pp.Ports[tp]); i++ {
+ startIndex := 0
</code_context>
<issue_to_address>
**issue (bug_risk):** GetNextPort ignores pp.Types ordering, which makes SetTheFirstPort’s type reordering ineffective for iteration
Since SetTheFirstPort mutates pp.Types to express type priority, GetNextPort should honor that same ordering. Right now it iterates numerically from `pos.tp` to `PortTypeCount`, ignoring pp.Types, so the cycle order no longer matches the priority you just established and may confuse users. Please update GetNextPort to iterate over pp.Types (starting from the current type and wrapping) or otherwise align its traversal with the ordering defined by SetTheFirstPort.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Pull request overview
该 PR 调整音频端口优先级策略,使“用户手动选择的端口”能被提升为最高优先级,并将每张声卡的默认输入/输出端口持久化,以便在端口列表刷新时复用这些偏好。
Changes:
- 移除“availablePort”显式可用端口跟踪,改为在刷新时清理不存在/不可用/禁用端口,并让优先级遍历直接基于清理后的列表。
- 新增按声卡维度持久化默认输入/输出端口(写入配置),并在刷新端口时按 PulseAudio priority + 默认端口对声卡端口做排序/调整。
- 调整
SetTheFirstPort行为:将指定端口(以及其类型)提升到优先级队首;同步更新相关单测与初始化调试输出。
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| audio1/priority_policy.go | 简化首选/遍历接口参数;调整插入与“置顶端口”逻辑 |
| audio1/priority_manager.go | 重写刷新逻辑:排序声卡端口、插入新端口、清理不存在端口;设置默认端口持久化 |
| audio1/config_keeper.go | CardConfig 增加默认输入/输出端口字段,并提供读写接口 |
| audio1/config_keeper_test.go | 更新 Save 序列化断言以包含新增字段 |
| audio1/priority_test.go | 更新 SetTheFirstPort/GetTheFirstPort 测试以适配新签名与语义 |
| audio1/card.go | 移除 update() 内的端口优先级排序调用 |
| audio1/audio.go | 初始化时移除一次额外的优先级打印 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cfff0cc to
649a40a
Compare
之前做音频端口优先级优化时, 忽略了产品需要, 要求将设置的端口放到端口类型优先级队首. Log: 音频端口优先级策略调整 PMS: BUG-351629 Influence: audio priority
deepin pr auto review代码审查意见总体评价这段代码主要对音频端口优先级管理进行了重构,改进了端口排序、默认端口处理和可用性检查机制。整体代码结构清晰,但在一些细节上还有优化空间。 详细审查意见1. 语法和逻辑问题1.1
|
之前做音频端口优先级优化时, 忽略了产品需要, 要求将设置的端口放到端口类型优先级队首.
Log: 音频端口优先级策略调整
PMS: BUG-351629
Influence: audio priority
Summary by Sourcery
Adjust audio port priority handling so user-selected ports are treated as highest priority and persisted as per-card defaults.
New Features:
Bug Fixes:
Enhancements: