diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py
index d00d22cf..a74e85f9 100644
--- a/src/octoprint/plugins/softwareupdate/__init__.py
+++ b/src/octoprint/plugins/softwareupdate/__init__.py
@@ -17,7 +17,7 @@ from . import version_checks, updaters, exceptions, util
from octoprint.server.util.flask import restricted_access
-from octoprint.server import admin_permission
+from octoprint.server import admin_permission, user_permission
from octoprint.util import dict_merge
import octoprint.settings
@@ -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,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
#~~ BluePrint API
@octoprint.plugin.BlueprintPlugin.route("/check", methods=["GET"])
+ @restricted_access
+ @user_permission.require(403)
def check_for_update(self):
if "check" in flask.request.values:
check_targets = map(str.strip, flask.request.values["check"].split(","))
@@ -101,7 +105,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 +132,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
@@ -382,7 +385,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
if target in checks:
# TODO make this cleaner, right now it saves too much to disk
checks[target]["current"] = target_version
- self._settings.set(["checks"], checks)
+ self._settings.set(["checks", target], checks[target])
# we have to save here (even though that makes us save quite often) since otherwise the next
# load will overwrite our changes we just made
diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js
index b8f0c3c6..cf5cd7f8 100644
--- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js
+++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js
@@ -89,6 +89,82 @@ $(function() {
self.config_cacheTtl(self.settings.settings.plugins.softwareupdate.cache_ttl());
};
+ self.fromCheckResponse = 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 += "
";
+ _.each(self.versions.items(), function(update_info) {
+ if (update_info.updateAvailable) {
+ var displayName = update_info.key;
+ if (update_info.hasOwnProperty("displayName")) {
+ displayName = update_info.displayName;
+ }
+ text += "- " + displayName + (update_info.updatePossible ? " " : "") + "
";
+ }
+ });
+ 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.performCheck = function(showIfNothingNew, force, ignoreSeen) {
if (!self.loginState.isUser()) return;
@@ -101,81 +177,7 @@ $(function() {
url: url,
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 += "";
- _.each(self.versions.items(), function(update_info) {
- if (update_info.updateAvailable) {
- var displayName = update_info.key;
- if (update_info.hasOwnProperty("displayName")) {
- displayName = update_info.displayName;
- }
- text += "- " + displayName + (update_info.updatePossible ? " " : "") + "
";
- }
- });
- 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"
- });
- }
- }
+ success: self.fromCheckResponse
});
};
@@ -421,6 +423,10 @@ $(function() {
self.updateInProgress = false;
break;
}
+ case "update_versions": {
+ self.performCheck();
+ break;
+ }
}
if (options != undefined) {
@@ -432,4 +438,4 @@ $(function() {
// view model class, parameters for constructor, container to bind to
ADDITIONAL_VIEWMODELS.push([SoftwareUpdateViewModel, ["loginStateViewModel", "printerStateViewModel", "settingsViewModel"], document.getElementById("settings_plugin_softwareupdate")]);
-});
\ No newline at end of file
+});