From 1a4b890d4a6ea7f6c099866db459d24af18e7240 Mon Sep 17 00:00:00 2001 From: jneilliii Date: Fri, 29 Sep 2023 12:32:11 -0400 Subject: [PATCH] 4.1.2 (#58) fix issue where restarting the same file doesn't work with auto start disabled --- .../websocket/simplyprint.py | 30 ++++++++++--------- setup.py | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/octoprint_simplyprint/websocket/simplyprint.py b/octoprint_simplyprint/websocket/simplyprint.py index dfa388a..865130f 100644 --- a/octoprint_simplyprint/websocket/simplyprint.py +++ b/octoprint_simplyprint/websocket/simplyprint.py @@ -584,28 +584,30 @@ def _process_demand(self, demand: str, args: Dict[str, Any]) -> None: self._logger.debug(f"Invalid url in message") return file_id: Optional[str] = args.get("file_id") - if self.last_downloaded_file != file_id or file_id is None: + file_name: Optional[str] = args.get("file_name") + start = bool(args.get("auto_start", 0)) + + if file_id != self.last_downloaded_file or self.file_manager.file_exists(FileDestinations.LOCAL, f"SimplyPrint/{file_name}") is False: self.last_downloaded_file = file_id - skip_download = False + self._logger.debug(f"downloading file \"{file_name}\"") + self.file_handler.download_file(url, start) else: - skip_download = True - start = bool(args.get("auto_start", 0)) + self.file_handler.pending_file = f"SimplyPrint/{file_name}" + if start: + self._logger.debug(f"starting locally stored file \"{file_name}\"") + self._process_demand("start_print", {}) + else: + self._logger.debug(f"letting SP know \"{file_name}\" is ready") + self.send_sp("file_progress", {"state": "ready"}) if self.file_manager.folder_exists(FileDestinations.LOCAL, "SimplyPrint"): files = self.file_manager.list_files(FileDestinations.LOCAL, "SimplyPrint") for file, data in files["local"].items(): - if skip_download is False: - self._logger.debug(f"deleting locally stored file \"{file}\"") + if data["path"] != f"SimplyPrint/{file_name}": + self._logger.debug(f"purging \"{file}\"") self.file_manager.remove_file(FileDestinations.LOCAL, data["path"]) else: - self._logger.debug(f"selecting locally stored file \"{file}\"") - self.file_handler.pending_file = data["path"] - if start: - self._logger.debug(f"starting locally stored file \"{file}\"") - self._process_demand("start_print", {}) - return - - self.file_handler.download_file(url, start) + self._logger.debug(f"not purging {file}") elif demand == "start_print": def _on_start_finished(fut: asyncio.Future): diff --git a/setup.py b/setup.py index 11202c5..108800d 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module # Remember to bump the version in octoprint_simplyprint/__init__.py as well -plugin_version = "4.1.1" +plugin_version = "4.1.2" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module