feat: add mute and unmute power actions - #338
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
嘿——我发现了 1 个问题
面向 AI 代理的提示
请处理此次代码审查中的评论:
## 各条评论
### 评论 1
<location path="src-tauri/src/mxu_actions.rs" line_range="931-935" />
<code_context>
+ let commands: [(&str, &[&str]); 3] = [
+ ("wpctl", &["set-mute", "@DEFAULT_AUDIO_SINK@", mute_value]),
+ ("pactl", &["set-sink-mute", "@DEFAULT_SINK@", mute_value]),
+ ("amixer", &["set", "Master", amixer_value]),
+ ];
+
</code_context>
<issue_to_address>
**问题(更广泛的影响):** ALSA 回退逻辑会运行 `amixer set Master ...`,这会修改 ALSA 所选声卡上名为 `Master` 的混音器,而不一定是系统的默认输出设备。在具有多个声卡,或默认输出通过其他设备路由的机器上,该命令可能执行成功,但已配置的默认输出仍不会发生变化。
**触发条件:** 当 `wpctl` 和 `pactl` 不可用或执行失败,且系统具有多个声卡,或者默认输出不是第一张 ALSA 声卡时。
**建议修复:** 显式指定实际的默认 ALSA/Pulse 输出;或者,除非能够解析默认设备,否则应将此回退逻辑视为不受支持,而不是假定 ALSA 所选声卡上的 `Master` 混音器就是目标设备。
```suggestion
let commands: [(&str, &[&str]); 2] = [
("wpctl", &["set-mute", "@DEFAULT_AUDIO_SINK@", mute_value]),
("pactl", &["set-sink-mute", "@DEFAULT_SINK@", mute_value]),
];
```
</issue_to_address>请帮助我变得更有用!请在每条评论上点击 👍 或 👎,我会利用您的反馈来改进审查结果。
Original comment in English
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src-tauri/src/mxu_actions.rs" line_range="931-935" />
<code_context>
+ let commands: [(&str, &[&str]); 3] = [
+ ("wpctl", &["set-mute", "@DEFAULT_AUDIO_SINK@", mute_value]),
+ ("pactl", &["set-sink-mute", "@DEFAULT_SINK@", mute_value]),
+ ("amixer", &["set", "Master", amixer_value]),
+ ];
+
</code_context>
<issue_to_address>
**issue (broader_impact):** The ALSA fallback runs `amixer set Master ...`, which changes the mixer named `Master` on ALSA's selected card rather than necessarily the system's default output device. On machines with multiple sound cards or a default output routed through another device, the command can succeed while the configured default output remains unchanged.
**Triggers:** When `wpctl` and `pactl` are unavailable or fail, and the system has multiple audio cards or a default output that is not the first ALSA card.
**Suggested fix:** Target the actual default ALSA/Pulse output explicitly, or treat this fallback as unsupported unless the default device can be resolved instead of assuming the `Master` mixer on ALSA's selected card.
```suggestion
let commands: [(&str, &[&str]); 2] = [
("wpctl", &["set-mute", "@DEFAULT_AUDIO_SINK@", mute_value]),
("pactl", &["set-sink-mute", "@DEFAULT_SINK@", mute_value]),
];
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Stevvven777
marked this pull request as draft
September 1, 2026 04:55
Contributor
Author
|
Addressed the Sourcery review in e1fcf3e: removed the amixer fallback because it cannot reliably target the configured default output device. Linux now uses wpctl with pactl as the only fallback and reports failure when neither can set the default sink state. |
Stevvven777
marked this pull request as ready for review
September 1, 2026 05:07
Contributor
There was a problem hiding this comment.
你好——我发现了 1 个问题
面向 AI Agent 的提示词
请处理此次代码审查中的评论:
## 单独评论
### 评论 1
<location path="src-tauri/src/mxu_actions.rs" line_range="583" />
<code_context>
/// MXU_POWER custom action 回调函数
-/// 从 custom_action_param 中读取 power_action,执行关机/重启/息屏/睡眠操作
+/// 从 custom_action_param 中读取 power_action,执行关机/重启/息屏/睡眠/静音操作
fn mxu_power_action_fn(
_ctx: &maa_framework::context::Context,
</code_context>
<issue_to_address>
**小问题:** 回调函数文档列出了关机、重启、息屏、睡眠和静音,但遗漏了新支持的 `unmute` 操作,因此文档中记录的操作集合并不完整。
**建议修复:** 更新注释,同时提及静音和取消静音操作。
```suggestion
/// 从 custom_action_param 中读取 power_action,执行关机/重启/息屏/睡眠/静音/取消静音操作
```
</issue_to_address>请帮助我变得更有用!请在每条评论上点击 👍 或 👎,我会利用反馈来改进审查结果。
Original comment in English
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src-tauri/src/mxu_actions.rs" line_range="583" />
<code_context>
/// MXU_POWER custom action 回调函数
-/// 从 custom_action_param 中读取 power_action,执行关机/重启/息屏/睡眠操作
+/// 从 custom_action_param 中读取 power_action,执行关机/重启/息屏/睡眠/静音操作
fn mxu_power_action_fn(
_ctx: &maa_framework::context::Context,
</code_context>
<issue_to_address>
**nitpick:** The callback documentation lists shutdown, restart, screen-off, sleep, and mute, but omits the newly supported `unmute` action, so the documented action set is incomplete.
**Suggested fix:** Update the comment to mention both mute and unmute actions.
```suggestion
/// 从 custom_action_param 中读取 power_action,执行关机/重启/息屏/睡眠/静音/取消静音操作
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #337
Summary
The actions set a deterministic state instead of toggling it, so task behavior does not depend on the computer's previous mute state.
Implementation
IAudioEndpointVolume::SetMuteon the default render/console endpoint.osascriptwith explicit output mute state.wpctl, with apactlfallback.No new task or UI component is introduced; the two cases are added to the existing operation-type selector.
Testing
cargo fmt --checkpassed.Linux and macOS behavior has not been manually exercised locally; their platform branches are intended to be covered by the repository's cross-platform CI builds.
Sourcery 摘要
为跨平台添加“静音”和“取消静音”电源操作,并本地化任务选项。
新功能:
增强功能:
构建:
Original summary in English
Sourcery 摘要
为计算机电源任务添加跨平台且具有确定性的静音和取消静音操作。
新功能:
改进:
构建:
维护:
Original summary in English
Summary by Sourcery
Add deterministic cross-platform mute and unmute actions to the computer power task.
New Features:
Enhancements:
Build:
Chores: