Skip to content

feat: add mute and unmute power actions - #338

Merged
MistEO merged 3 commits into
MistEO:mainfrom
Stevvven777:feat/power-audio-mute
Sep 2, 2026
Merged

feat: add mute and unmute power actions#338
MistEO merged 3 commits into
MistEO:mainfrom
Stevvven777:feat/power-audio-mute

Conversation

@Stevvven777

@Stevvven777 Stevvven777 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Closes #337

Summary

  • Add explicit Mute and Unmute cases to the existing computer power task.
  • Set the default output device mute state on Windows, macOS, and Linux.
  • Add translations for all five built-in locales.

The actions set a deterministic state instead of toggling it, so task behavior does not depend on the computer's previous mute state.

Implementation

  • Windows: Core Audio IAudioEndpointVolume::SetMute on the default render/console endpoint.
  • macOS: osascript with explicit output mute state.
  • Linux: wpctl, with a pactl fallback.

No new task or UI component is introduced; the two cases are added to the existing operation-type selector.

Testing

  • Prettier check passed.
  • cargo fmt --check passed.
  • TypeScript type check passed.
  • Vite production build passed.
  • Windows x86_64 production Rust build with Tauri custom protocol passed.
  • Manually tested both actions with MaaEnd v2.4.0 on Windows x64.

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 摘要

为跨平台添加“静音”和“取消静音”电源操作,并本地化任务选项。

新功能:

  • 为现有的计算机电源任务添加明确的“静音”和“取消静音”操作。
  • 支持在 Windows、macOS 和 Linux 上设置默认音频输出的静音状态。
  • 在所有五种支持的语言环境中本地化新操作。

增强功能:

  • 通过设置请求的静音状态,而不是切换当前状态,使音频操作具有确定性。

构建:

  • 添加静音控制所需的 Windows 音频和 COM API 依赖项。
Original summary in English

Sourcery 摘要

为计算机电源任务添加跨平台且具有确定性的静音和取消静音操作。

新功能:

  • 为现有的计算机电源任务添加明确的“静音”和“取消静音”操作。
  • 支持在 Windows、macOS 和 Linux 上设置默认音频输出的静音状态。

改进:

  • 通过设置请求的静音状态,而不是切换当前状态,使音频控制具有确定性。

构建:

  • 添加静音控制所需的 Windows 音频和 COM 依赖项。

维护:

  • 在所有受支持的语言环境中本地化新增操作。
Original summary in English

Summary by Sourcery

Add deterministic cross-platform mute and unmute actions to the computer power task.

New Features:

  • Add explicit Mute and Unmute actions to the existing computer power task.
  • Support setting the default audio output mute state across Windows, macOS, and Linux.

Enhancements:

  • Make audio control deterministic by setting the requested mute state rather than toggling the current state.

Build:

  • Add the Windows audio and COM dependencies required for mute control.

Chores:

  • Localize the new actions in all supported locales.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嘿——我发现了 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>

Sourcery 对开源项目免费——如果您喜欢我们的审查结果,请考虑分享它们 ✨
请帮助我变得更有用!请在每条评论上点击 👍 或 👎,我会利用您的反馈来改进审查结果。
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>

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.

Comment thread src-tauri/src/mxu_actions.rs Outdated
@Stevvven777
Stevvven777 marked this pull request as draft September 1, 2026 04:55
@Stevvven777

Copy link
Copy Markdown
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
Stevvven777 marked this pull request as ready for review September 1, 2026 05:07

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好——我发现了 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>

Sourcery 对开源项目免费提供服务——如果你喜欢我们的审查结果,请考虑分享给他人 ✨
请帮助我变得更有用!请在每条评论上点击 👍 或 👎,我会利用反馈来改进审查结果。
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>

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.

Comment thread src-tauri/src/mxu_actions.rs Outdated
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@MistEO
MistEO merged commit 72a6090 into MistEO:main Sep 2, 2026
9 checks passed
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.

功能建议:为“电脑操作”增加静音与解除静音

2 participants