Initial work on config update
All checks were successful
Check / mypy (push) Successful in 48s
Check / ruff (push) Successful in 5s

This commit is contained in:
Christoph Stahl 2025-05-25 10:40:06 +02:00
parent b2a58a5537
commit fe6539de35
3 changed files with 35 additions and 3 deletions

View file

@ -152,6 +152,7 @@ class State:
waiting_room: list[Entry] = field(default_factory=list)
recent: list[Entry] = field(default_factory=list)
config: dict[str, Any] = field(default_factory=default_config)
old_config: dict[str, Any] = field(default_factory=default_config)
class Client:
@ -257,6 +258,23 @@ class Client:
"""
self.state.config = default_config() | data
async def send_update_config(self) -> None:
"""
Send the current configuration to the server.
This is used to update the server with the current configuration of the
client. This is done by sending a "update_config" message to the server.
:rtype: None
"""
changes = dict()
for key, value in self.state.config.items():
if key in default_config() and default_config()[key] != value:
changes[key] = value
await self.sio.emit("update_config", self.state.config)
async def handle_skip_current(self, data: dict[str, Any]) -> None:
"""
Handle the "skip-current" message.
@ -337,6 +355,10 @@ class Client:
:rtype: None
"""
# stop running mpv instances
await self.kill_mpv()
logger.info("Connected to server")
data = {
"queue": self.state.queue,
@ -583,7 +605,7 @@ class Client:
async def kill_mpv(self) -> None:
"""
Kill the mpv process. Needs to be called in a thread, because of mpv...
Kill the mpv process. Needs to be called in a seperate thread, because of mpv...
See https://github.com/jaseg/python-mpv/issues/114#issuecomment-1214305952
:rtype: None

View file

@ -504,7 +504,6 @@ class GeneralConfig(OptionFrame):
["debug", "info", "warning", "error", "critical"],
config["log_level"],
)
# self.add_bool_option("show_advanced", "Show Advanced Options", config["show_advanced"])
self.simple_options = ["server", "room", "secret"]
@ -568,6 +567,10 @@ class SyngGui(QMainWindow):
self.print_queue_button.clicked.connect(self.debug_print_queue)
self.buttons_layout.addWidget(self.print_queue_button)
self.update_config_button = QPushButton("Update Config")
self.update_config_button.clicked.connect(self.update_config)
self.update_config_button.setVisible(False)
self.buttons_layout.addWidget(self.update_config_button)
self.startbutton = QPushButton("Connect")
self.startbutton.clicked.connect(self.start_syng_client)
@ -831,9 +834,16 @@ class SyngGui(QMainWindow):
self.set_client_button_stop()
def set_client_button_stop(self) -> None:
self.update_config_button.setVisible(True)
self.general_config.string_options["server"].setEnabled(False)
self.general_config.string_options["room"].setEnabled(False)
self.startbutton.setText("Disconnect")
def set_client_button_start(self) -> None:
self.general_config.string_options["server"].setEnabled(True)
self.general_config.string_options["room"].setEnabled(True)
self.update_config_button.setVisible(False)
self.startbutton.setText("Connect")
def start_syng_client(self) -> None:

View file

@ -108,7 +108,7 @@ class Queue:
def find_by_name(self, name: str) -> Optional[Entry]:
"""
Find an entry by its performer and return it.
Find the first entry by its performer and return it.
:param name: The name of the performer to search for.
:type name: str