diff --git a/syng/client.py b/syng/client.py index 4bf61b4..b7540fc 100644 --- a/syng/client.py +++ b/syng/client.py @@ -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 diff --git a/syng/gui.py b/syng/gui.py index 1c71bad..3b747c2 100644 --- a/syng/gui.py +++ b/syng/gui.py @@ -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: diff --git a/syng/queue.py b/syng/queue.py index d7e5566..0e4edfc 100644 --- a/syng/queue.py +++ b/syng/queue.py @@ -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