diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index d00d22cf..76264435 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -43,6 +43,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, def refresh_checks(name, plugin): self._refresh_configured_checks = True + self._send_client_message("update_versions") + self._plugin_lifecycle_manager.add_callback("enabled", refresh_checks) self._plugin_lifecycle_manager.add_callback("disabled", refresh_checks) @@ -92,6 +94,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, #~~ BluePrint API @octoprint.plugin.BlueprintPlugin.route("/check", methods=["GET"]) + @restricted_access def check_for_update(self): if "check" in flask.request.values: check_targets = map(str.strip, flask.request.values["check"].split(",")) @@ -101,7 +104,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, if "force" in flask.request.values and flask.request.values["force"] in octoprint.settings.valid_boolean_trues: force = True else: - force=False + force = False try: information, update_available, update_possible = self.get_current_versions(check_targets=check_targets, force=force) @@ -128,9 +131,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, else: check_targets = None - if "force" in json_data: - from octoprint.settings import valid_boolean_trues - force = (json_data["force"] in valid_boolean_trues) + if "force" in json_data and json_data["force"] in octoprint.settings.valid_boolean_trues: + force = True else: force = False diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index 74472574..19c88137 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -44,9 +44,7 @@ $(function() { }; self._showPopup = function(options, eventListeners) { - if (self.popup !== undefined) { - self.popup.remove(); - } + self._closePopup(); self.popup = new PNotify(options); if (eventListeners) { @@ -65,6 +63,12 @@ $(function() { } }; + self._closePopup = function() { + if (self.popup !== undefined) { + self.popup.remove(); + } + }; + self.showPluginSettings = function() { self._copyConfig(); self.configurationDialog.modal(); @@ -89,6 +93,86 @@ $(function() { self.config_cacheTtl(self.settings.settings.plugins.softwareupdate.cache_ttl()); }; + self.fromCheckResponse = function(data, ignoreSeen, showIfNothingNew) { + var versions = []; + _.each(data.information, function(value, key) { + value["key"] = key; + + if (!value.hasOwnProperty("displayName") || value.displayName == "") { + value.displayName = value.key; + } + if (!value.hasOwnProperty("displayVersion") || value.displayVersion == "") { + value.displayVersion = value.information.local.name; + } + + versions.push(value); + }); + self.versions.updateItems(versions); + + if (data.status == "updateAvailable" || data.status == "updatePossible") { + var text = gettext("There are updates available for the following components:"); + + text += ""; + + text += "" + gettext("Those components marked with can be updated directly.") + ""; + + var options = { + title: gettext("Update Available"), + text: text, + hide: false + }; + var eventListeners = {}; + + if (data.status == "updatePossible" && self.loginState.isAdmin()) { + // if user is admin, add action buttons + options["confirm"] = { + confirm: true, + buttons: [{ + text: gettext("Ignore"), + click: function() { + self._markNotificationAsSeen(data.information); + self._showPopup({ + text: gettext("You can make this message display again via \"Settings\" > \"SoftwareUpdate\" > \"Check for update now\"") + }); + } + }, { + text: gettext("Update now"), + addClass: "btn-primary", + click: self.update + }] + }; + options["buttons"] = { + closer: false, + sticker: false + }; + } + + if (ignoreSeen || !self._hasNotificationBeenSeen(data.information)) { + self._showPopup(options, eventListeners); + } + } else if (data.status == "current") { + if (showIfNothingNew) { + self._showPopup({ + title: gettext("Everything is up-to-date"), + hide: false, + type: "success" + }); + } else { + self._closePopup(); + } + } + }; + self.performCheck = function(showIfNothingNew, force, ignoreSeen) { if (!self.loginState.isUser()) return; @@ -102,79 +186,7 @@ $(function() { type: "GET", dataType: "json", success: function(data) { - var versions = []; - _.each(data.information, function(value, key) { - value["key"] = key; - - if (!value.hasOwnProperty("displayName") || value.displayName == "") { - value.displayName = value.key; - } - if (!value.hasOwnProperty("displayVersion") || value.displayVersion == "") { - value.displayVersion = value.information.local.name; - } - - versions.push(value); - }); - self.versions.updateItems(versions); - - if (data.status == "updateAvailable" || data.status == "updatePossible") { - var text = gettext("There are updates available for the following components:"); - - text += ""; - - text += "" + gettext("Those components marked with can be updated directly.") + ""; - - var options = { - title: gettext("Update Available"), - text: text, - hide: false - }; - var eventListeners = {}; - - if (data.status == "updatePossible" && self.loginState.isAdmin()) { - // if user is admin, add action buttons - options["confirm"] = { - confirm: true, - buttons: [{ - text: gettext("Ignore"), - click: function() { - self._markNotificationAsSeen(data.information); - self._showPopup({ - text: gettext("You can make this message display again via \"Settings\" > \"SoftwareUpdate\" > \"Check for update now\"") - }); - } - }, { - text: gettext("Update now"), - addClass: "btn-primary", - click: self.update - }] - }; - options["buttons"] = { - closer: false, - sticker: false - }; - } - - if (ignoreSeen || !self._hasNotificationBeenSeen(data.information)) { - self._showPopup(options, eventListeners); - } - } else if (data.status == "current" && showIfNothingNew) { - self._showPopup({ - title: gettext("Everything is up-to-date"), - hide: false, - type: "success" - }); - } + self.fromCheckResponse(data, ignoreSeen, showIfNothingNew); } }); }; @@ -421,6 +433,10 @@ $(function() { self.updateInProgress = false; break; } + case "update_versions": { + self.performCheck(); + break; + } } if (options != undefined) {