From 631a408adad039171513efbc2fd53d8aac4dc6d3 Mon Sep 17 00:00:00 2001 From: Christoph Stahl Date: Wed, 15 Nov 2023 02:17:55 +0100 Subject: [PATCH] Client stopping stops now also the mpv process --- syng/client.py | 22 ++++++++++++++++++---- syng/gui.py | 8 ++++---- syng/sources/files.py | 3 ++- syng/sources/s3.py | 1 + 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/syng/client.py b/syng/client.py index af7a55f..48d216e 100644 --- a/syng/client.py +++ b/syng/client.py @@ -48,6 +48,7 @@ from typing import Optional import qrcode import socketio +import engineio from PIL import Image from . import jsonencoder @@ -375,8 +376,11 @@ async def handle_request_config(data: dict[str, Any]) -> None: await sio.emit("config", {"source": data["source"], "config": config}) -def terminate(*args): - print("OOPS") +def signal_handler(): + engineio.async_client.async_signal_handler() + if state.current_source is not None: + if state.current_source.player is not None: + state.current_source.player.kill() async def start_client(config: dict[str, Any]) -> None: @@ -408,8 +412,18 @@ async def start_client(config: dict[str, Any]) -> None: state.config["key"] = "" await sio.connect(state.config["server"]) - await sio.wait() - print("exit") + + asyncio.get_event_loop().add_signal_handler(signal.SIGINT, signal_handler) + asyncio.get_event_loop().add_signal_handler(signal.SIGTERM, signal_handler) + + try: + await sio.wait() + except asyncio.CancelledError: + pass + finally: + if state.current_source is not None: + if state.current_source.player is not None: + state.current_source.player.kill() def create_async_and_start_client(config): diff --git a/syng/gui.py b/syng/gui.py index 7a1cf19..f248919 100644 --- a/syng/gui.py +++ b/syng/gui.py @@ -322,10 +322,10 @@ class SyngGui(customtkinter.CTk): ) self.startbutton.pack(side="right") - startserverbutton = customtkinter.CTkButton( - fileframe, text="Start Server", command=self.start_server - ) - startserverbutton.pack(side="right") + # startserverbutton = customtkinter.CTkButton( + # fileframe, text="Start Server", command=self.start_server + # ) + # startserverbutton.pack(side="right") open_web_button = customtkinter.CTkButton( fileframe, text="Open Web", command=self.open_web diff --git a/syng/sources/files.py b/syng/sources/files.py index f5775e2..0d0101a 100644 --- a/syng/sources/files.py +++ b/syng/sources/files.py @@ -18,7 +18,8 @@ class FilesSource(FileBasedSource): source_name = "files" config_schema = FileBasedSource.config_schema | { - "dir": (str, "Directory to index", ".") + "dir": (str, "Directory to index", "."), + "index_file": (str, "Index file", "files-index"), } def __init__(self, config: dict[str, Any]): diff --git a/syng/sources/s3.py b/syng/sources/s3.py index 5147753..f3c103b 100644 --- a/syng/sources/s3.py +++ b/syng/sources/s3.py @@ -41,6 +41,7 @@ class S3Source(FileBasedSource): "secure": (bool, "Use SSL", True), "bucket": (str, "Bucket of the s3", ""), "tmp_dir": (str, "Folder for\ntemporary download", "/tmp/syng"), + "index_file": (str, "Index file", "s3-index"), } def __init__(self, config: dict[str, Any]):