From 9c27d47beeb13bdd5bfbf91e4833fe529a0fa5b3 Mon Sep 17 00:00:00 2001 From: Lenoch <81lennoch@gmail.com> Date: Mon, 16 Dec 2024 21:46:19 +0100 Subject: [PATCH] Add support for volume mute button on Linux - Added support for muting volume on Linux - Implemented mute_volume function in volume.py - Updated handle_command to also handle "/volume mute" command - Updated commands.json to use "/volume mute" command instead of "/soundcontrol mute" by default --- app/buttons/audio/volume.py | 29 ++++++++++++++++++++++++++++- app/buttons/commands.py | 5 +---- webdeck/commands.json | 2 +- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/app/buttons/audio/volume.py b/app/buttons/audio/volume.py index 201f6a5..547d746 100644 --- a/app/buttons/audio/volume.py +++ b/app/buttons/audio/volume.py @@ -3,6 +3,10 @@ import time import math import ctypes +import keyboard +import os +if not is_linux or os.environ.get("DISPLAY"): + import pyautogui if is_windows: import win32api import win32con @@ -103,6 +107,26 @@ def decrease_volume(delta=1): raise NotImplementedError("This command is not implemented for this platform.") +def mute_volume(): + if is_windows: + try: + keyboard.send("volume mute") + except Exception: + try: + keyboard.send(-173) + except Exception: + pyautogui.press("volumemute") + + elif is_linux: + try: + keyboard.send("volume mute") + except Exception: + keyboard.send(113) + + else: + raise NotImplementedError("This command is not implemented for this platform.") + + def handle_command(message): if message.startswith("/volume +"): delta = message.replace("/volume +", "").strip() @@ -116,4 +140,7 @@ def handle_command(message): elif message.startswith("/volume set"): target_volume = int(message.replace("/volume set ", "")) / 100.0 - set_volume(target_volume) \ No newline at end of file + set_volume(target_volume) + + elif message.startswith("/volume mute"): + mute_volume() diff --git a/app/buttons/commands.py b/app/buttons/commands.py index 2632920..c3ccb40 100644 --- a/app/buttons/commands.py +++ b/app/buttons/commands.py @@ -172,9 +172,6 @@ def handle_command(message=None): log.debug("New volume: %s" % volume.GetMasterVolume()) comtypes.CoUninitialize() - - elif message.startswith("/soundcontrol mute"): - pyautogui.press("volumemute") elif message.startswith("/mediacontrol"): audio.media_control(message) @@ -239,7 +236,7 @@ def handle_command(message=None): pyautogui.hotkey("win", "v") else: - if message.startswith("/volume"): + if message.startswith(("/volume", "/soundcontrol mute")): audio.change_volume(message) elif message.startswith("/spotify"): diff --git a/webdeck/commands.json b/webdeck/commands.json index 7e34be7..b6a9d0a 100644 --- a/webdeck/commands.json +++ b/webdeck/commands.json @@ -381,7 +381,7 @@ } }, { - "command": "/soundcontrol mute", + "command": "/volume mute", "args": [], "style": { "image": "volume-mute.svg",