diff --git a/octoprint_mkswifisdcard/__init__.py b/octoprint_mkswifisdcard/__init__.py index 8dc88ce..6ddf5ba 100644 --- a/octoprint_mkswifisdcard/__init__.py +++ b/octoprint_mkswifisdcard/__init__.py @@ -50,7 +50,7 @@ def change_state_handler(event, data): def set_upload_progress(progress): self._plugin_manager.send_plugin_message( - "mkswifisdcard", dict(progress=int(progress)) + self._identifier, dict(progress=int(progress)) ) def run_upload(): @@ -69,16 +69,23 @@ def run_upload(): return remote_name def upload_via_wifi(self, path, filename, host, callback): - res = requests.post( - url="http://%s/upload?X-Filename=%s" % (host, filename), - data=ProgressUpload(path, callback), - headers={ - "Content-Type": "application/octet-stream", - "Connection": "keep-alive", - }, - ) + try: + res = requests.post( + url="http://%s/upload?X-Filename=%s" % (host, filename), + data=ProgressUpload(path, callback), + headers={ + "Content-Type": "application/octet-stream", + "Connection": "keep-alive", + }, + timeout=60 + ) + except Exception as e: + self._logger.exception("Uploading to sdwire failed: {}".format(e)) + self.notify_error_to_user("Uploading to sdwire failed: {}".format(e)) - + def notify_error_to_user(self, message): + self._plugin_manager.send_plugin_message(self._identifier, dict(error=message)) + # TemplatePlugin mixin def get_template_configs(self): return [{"type": "settings", "custom_bindings": False}] @@ -93,6 +100,24 @@ def get_assets(self): # core UI here. return {"js": ["js/mkswifisdcard.js"]} + # Softwareupdate hook + def get_update_information(self): + return { + "mkswifisdcard": { + "displayName": "mkswifisdcard", + "displayVersion": self._plugin_version, + + # version check: github repository + "type": "github_release", + "user": "om2804", + "repo": "octoPrint-mkswifisdcard", + "current": self._plugin_version, + + # update method: pip + "pip": "https://github.com/om2804/octoprint_mkswifisdcard/archive/{target_version}.zip", + } + } + class ProgressUpload: def __init__(self, filename, callback, chunk_size=1048576): @@ -113,6 +138,7 @@ def __len__(self): return self.file_size + # Set the Python version your plugin is compatible with below. Recommended is Python 3 only for all new plugins. # OctoPrint 1.8.0 onwards only supports Python 3. __plugin_pythoncompat__ = ">=3,<4" # Only Python 3 @@ -124,5 +150,6 @@ def __plugin_load__(): global __plugin_hooks__ __plugin_hooks__ = { - "octoprint.printer.sdcardupload": __plugin_implementation__.custom_upload_to_sd + "octoprint.printer.sdcardupload": __plugin_implementation__.custom_upload_to_sd, + "octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information } diff --git a/octoprint_mkswifisdcard/static/js/mkswifisdcard.js b/octoprint_mkswifisdcard/static/js/mkswifisdcard.js index 438e622..b8e5725 100644 --- a/octoprint_mkswifisdcard/static/js/mkswifisdcard.js +++ b/octoprint_mkswifisdcard/static/js/mkswifisdcard.js @@ -16,6 +16,14 @@ $(function () { self.filesViewModel._setProgressBar(data["progress"], 'Uploading to sd - ' + data["progress"] + '%...', false); } + if (data.hasOwnProperty("error")) { + new PNotify({ + title: 'MKS WiFi SD-card Error', + text: '

Error of uploading to sd-card over WiFi. Check your settings.

'+data["error"]+'

', + hide: true + }); + return; + } } }