-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for playpause button on Linux and refactor media controls
- Added support for playpause button on Linux - Moved playpause, prevtrack, and nexttrack functions to a dedicated media.py file - Updated import statements in __init__.py to include media control - Refactored handle_command in commands.py to use media_control from media.py
- Loading branch information
Showing
3 changed files
with
40 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .set_system_mic import set_microphone_by_name | ||
from .set_system_speaker import set_speakers_by_name | ||
from .volume import handle_command as change_volume | ||
from .volume import handle_command as change_volume | ||
from .media import handle_command as media_control |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from app.utils.platform import is_linux | ||
|
||
import os | ||
import keyboard | ||
if not is_linux or os.environ.get("DISPLAY"): | ||
import pyautogui | ||
|
||
|
||
def handle_command(message): | ||
|
||
if message.startswith("/mediacontrol playpause"): | ||
playpause() | ||
elif message.startswith("/mediacontrol previous"): | ||
prevtrack() | ||
elif message.startswith("/mediacontrol next"): | ||
nexttrack() | ||
|
||
|
||
def playpause(): | ||
try: | ||
if is_linux: | ||
keyboard.send("play/pause media") | ||
else: | ||
pyautogui.press("playpause") | ||
except: | ||
if is_linux: | ||
keyboard.send(164) | ||
else: | ||
keyboard.send(-179) | ||
|
||
def prevtrack(): | ||
pyautogui.press("prevtrack") | ||
|
||
def nexttrack(): | ||
pyautogui.press("nexttrack") |
This file contains 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