diff --git a/src/pyvtt/send_cmd.py b/src/pyvtt/send_cmd.py index 547b962..debf045 100755 --- a/src/pyvtt/send_cmd.py +++ b/src/pyvtt/send_cmd.py @@ -2,10 +2,12 @@ import socket import sys import argparse from pyvtt.configuration import read_configurations +from typing import Optional CONFIGURATION = read_configurations() -def send_cmd(cmd: str, socket_path: str): + +def send_cmd(cmd: str, socket_path: str, preset: Optional[str] = None) -> None: """ Sends a command to a Unix domain socket server. @@ -26,6 +28,8 @@ def send_cmd(cmd: str, socket_path: str): with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client: client.settimeout(3) client.connect(socket_path) + if preset: + cmd = f"{cmd}::::{preset}" client.sendall(cmd.encode()) except FileNotFoundError: print(f"Error: The socket file '{socket_path}' does not exist.", file=sys.stderr, flush=True) @@ -47,6 +51,15 @@ def main(): default="toggle", help="The command to send to the server (default: toggle).", ) + + parser.add_argument( + "preset", + nargs="?", + default=None, + help="The preset to use (optional)." + ) + + args = parser.parse_args() - send_cmd(args.command, CONFIGURATION["socket_path"]) \ No newline at end of file + send_cmd(args.command, CONFIGURATION["socket_path"], args.preset) \ No newline at end of file diff --git a/src/pyvtt/voice_to_text_tray.py b/src/pyvtt/voice_to_text_tray.py index c588c1b..425bcb2 100755 --- a/src/pyvtt/voice_to_text_tray.py +++ b/src/pyvtt/voice_to_text_tray.py @@ -166,6 +166,15 @@ class SocketListener(threading.Thread): conn, _ = self.sock.accept() with conn: data = conn.recv(1024).decode().strip() + if data: + cmd = data.split("::::") + if len(cmd) > 1: + data = cmd[0] + preset = cmd[1] + if preset in [p["name"] for p in CONFIGURATION["presets"]]: + self.tray_app.set_preset([p["name"] for p in CONFIGURATION["presets"]].index(preset)) + else: + data = cmd[0] if data == "toggle": self.tray_app.toggle_recording() elif data == "start":