Skip to content

Commit

Permalink
Add support for volume mute button on Linux
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Lenochxd committed Dec 16, 2024
1 parent b39333a commit 9c27d47
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
29 changes: 28 additions & 1 deletion app/buttons/audio/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)
set_volume(target_volume)

elif message.startswith("/volume mute"):
mute_volume()
5 changes: 1 addition & 4 deletions app/buttons/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"):
Expand Down
2 changes: 1 addition & 1 deletion webdeck/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
}
},
{
"command": "/soundcontrol mute",
"command": "/volume mute",
"args": [],
"style": {
"image": "volume-mute.svg",
Expand Down

0 comments on commit 9c27d47

Please sign in to comment.