diff --git a/octoprint_karmen/__init__.py b/octoprint_karmen/__init__.py index bdd851b..01560d8 100644 --- a/octoprint_karmen/__init__.py +++ b/octoprint_karmen/__init__.py @@ -3,6 +3,7 @@ from octoprint.settings import settings import octoprint.plugin +from octoprint.util.version import is_octoprint_compatible from .websocket_proxy import Connector from .utils import SentryWrapper @@ -38,6 +39,7 @@ def get_template_vars(self): else: key_redacted = (key[:2] + "*" * (len(key) - 4) + key[-2:]) if key else None return { + "is_octoprint_compatible": self.is_octoprint_compatible, "ws_server": self._settings.get(["ws_server"]), "path_whitelist": list(filter(None, self._settings.get(["path_whitelist"]).split(";"))), "api_port": self.port, @@ -107,8 +109,10 @@ def ws_proxy_connect(self): api_url = f"{self.host}:{self.port}" url = f"{ws_server_url}/{key}" if not key: - self._logger.info("No Karmen device key provided; Not connecting.") + self._logger.warning("No Karmen device key provided.") return + if not self.is_octoprint_compatible: + self._logger.warning("Incompatible octoprint.") self.con = Connector(url, api_url, self._logger, self._settings.get(["path_whitelist"]), self.sentry) self.con.connect() @@ -119,6 +123,7 @@ def ws_proxy_reconnect(self): self.ws_proxy_connect() def on_startup(self, host, port): + self.is_octoprint_compatible = is_octoprint_compatible(">1.8") self.con = None self.host = host self.port = port diff --git a/octoprint_karmen/static/js/karmen.js b/octoprint_karmen/static/js/karmen.js index 720d034..1e694d4 100644 --- a/octoprint_karmen/static/js/karmen.js +++ b/octoprint_karmen/static/js/karmen.js @@ -4,26 +4,80 @@ * Author: Pavel Vojacek * License: MIT */ -$(function() { +$(function () { function KarmenViewModel(parameters) { var self = this; + let performCheck = function () { + OctoPrint.system.getInfo().then((info) => { + function versionCompare(v1, v2, options) { + var lexicographical = options && options.lexicographical, + zeroExtend = options && options.zeroExtend, + v1parts = v1.split('.'), + v2parts = v2.split('.'); - // assign the injected parameters, e.g.: - // self.loginStateViewModel = parameters[0]; - // self.settingsViewModel = parameters[1]; + function isValidPart(x) { + return (lexicographical ? /^\d+[A-Za-z]*$/ : /^\d+$/).test(x); + } - // TODO: Implement your plugin's view model here. + if (!v1parts.every(isValidPart) || !v2parts.every(isValidPart)) { + return NaN; + } + + if (zeroExtend) { + while (v1parts.length < v2parts.length) v1parts.push("0"); + while (v2parts.length < v1parts.length) v2parts.push("0"); + } + + if (!lexicographical) { + v1parts = v1parts.map(Number); + v2parts = v2parts.map(Number); + } + + for (var i = 0; i < v1parts.length; ++i) { + if (v2parts.length == i) { + return 1; + } + + if (v1parts[i] == v2parts[i]) { + continue; + } + else if (v1parts[i] > v2parts[i]) { + return 1; + } + else { + return -1; + } + } + + if (v1parts.length != v2parts.length) { + return -1; + } + + return 0; + } + + let version = info.systeminfo["octoprint.version"] + if (versionCompare(version, "1.8") < 0) { + self.notify = new PNotify({ + text:`This version of Karmen Connector is not supported in Octoprint version ${version}. + Please upgrade to Octoprint 1.8+ or use legacy plugin. + Check plugin settings for details.`, + title: "Karmen Connector", + type: "error", + delay: 10000, + }); + } + }); + } + + self.onUserLoggedIn = function () { + performCheck(); + } } - /* view model class, parameters for constructor, container to bind to - * Please see http://docs.octoprint.org/en/master/plugins/viewmodels.html#registering-custom-viewmodels for more details - * and a full list of the available options. - */ OCTOPRINT_VIEWMODELS.push({ construct: KarmenViewModel, - // ViewModels your plugin depends on, e.g. loginStateViewModel, settingsViewModel, ... - dependencies: [ /* "loginStateViewModel", "settingsViewModel" */ ], - // Elements to bind to, e.g. #settings_plugin_karmen, #tab_plugin_karmen, ... - elements: [ /* ... */ ] + dependencies: ["settingsViewModel", "loginStateViewModel"], + elements: [ /* ... */] }); }); diff --git a/octoprint_karmen/templates/karmen_settings.jinja2 b/octoprint_karmen/templates/karmen_settings.jinja2 index 358c3ee..073b1cb 100644 --- a/octoprint_karmen/templates/karmen_settings.jinja2 +++ b/octoprint_karmen/templates/karmen_settings.jinja2 @@ -34,6 +34,7 @@ +{% if is_octoprint_compatible %}

@@ -94,3 +95,17 @@

Never share your API or device keys with ANYONE.

Please follow our guidelines and do not use the primary Octoprint key when setting up the Karmen plugin. Rather, create a special key for that purpose as described in our documentation

+{% else %} +
+

This version is incompatible with Octoprint 1.7 and lower

+

You can:

+ +

To install version 0.4.0 go to Octoprint Settings -> Plugin Manager -> + Get more and to ... from URL field enter + https://github.com/fragaria/karmen-octoprint-plugin/archive/refs/tags/0.4.0-legacy.zip and click Install +

+
+{% endif %} \ No newline at end of file diff --git a/setup.py b/setup.py index 37243bb..a31808f 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ plugin_license = "MIT" # Any additional requirements besides OctoPrint should be listed here -plugin_requires = ['Octoprint>=1.8',] +plugin_requires = [] ### -------------------------------------------------------------------------------------------------------------------- ### More advanced options that you usually shouldn't have to touch follow after this point