From f3f640c24f986f30f55864d6c3939bbdcd373a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 19 Nov 2014 09:16:37 +0100 Subject: [PATCH] On reconnect to server, check if the version changed and if so hard-reload the UI --- src/octoprint/static/js/app/dataupdater.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/octoprint/static/js/app/dataupdater.js b/src/octoprint/static/js/app/dataupdater.js index 9a709017..60bae471 100644 --- a/src/octoprint/static/js/app/dataupdater.js +++ b/src/octoprint/static/js/app/dataupdater.js @@ -105,6 +105,7 @@ function DataUpdater(allViewModels) { headers: {"X-Api-Key": UI_API_KEY} }); + var oldVersion = VERSION; VERSION = data["version"]; DISPLAY_VERSION = data["display_version"]; $("span.version").text(DISPLAY_VERSION); @@ -122,6 +123,15 @@ function DataUpdater(allViewModels) { } } + if (oldVersion != VERSION) { + // version change detected, force reloading UI - use randomized delay to reduce server load in + // the case of multiple clients + var delay = Math.floor(Math.random() * 5) + 1; + setTimeout(function() {location.reload(true);}, delay * 1000); + + // TODO notify about that, or show confirmation + } + break; } case "history": { @@ -175,7 +185,7 @@ function DataUpdater(allViewModels) { new PNotify({title: gettext("Timelapse ready"), text: _.sprintf(gettext("New timelapse %(movie_basename)s is done rendering."), payload)}); timelapseViewModel.requestData(); } else if (type == "MovieFailed") { - html = "

" + _.sprintf(gettext("Rendering of timelapse %(movie_basename)s failedwith return code %(returncode)s"), payload) + "

"; + html = "

" + _.sprintf(gettext("Rendering of timelapse %(movie_basename)s failed with return code %(returncode)s"), payload) + "

"; html += pnotifyAdditionalInfo('
' + payload.error + '
'); new PNotify({title: gettext("Rendering failed"), text: html, type: "error", hide: false}); } else if (type == "SlicingStarted") {