From cf7f72e2405ade3da6129acb6061c89bf0dcc553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 27 Mar 2023 18:33:23 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Remember=20last=20shown=20webcam?= =?UTF-8?q?=20on=20the=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See #4778 --- .../static/js/app/viewmodels/control.js | 19 +++++++++++++++++++ src/octoprint/templates/tabs/control.jinja2 | 7 ++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/control.js b/src/octoprint/static/js/app/viewmodels/control.js index 554dab821..107d28c6d 100644 --- a/src/octoprint/static/js/app/viewmodels/control.js +++ b/src/octoprint/static/js/app/viewmodels/control.js @@ -75,7 +75,26 @@ $(function () { } }; + const selectedCameraStorageKey = "core.control.selectedCamera"; + self.selectDefaultWebcam = function () { + let div = localStorage[selectedCameraStorageKey]; + + if (!div || document.getElementById(div.slice(1)) === null) { + div = undefined; + } + + if (div !== undefined) { + $(`${div}_link a`).tab("show"); + } else { + $("#webcam_plugins_container .nav li:first a").tab("show"); + } + }; + self.onStartupComplete = function () { + $("#webcam_plugins_container .nav a[data-toggle='tab']").on("shown", (e) => { + localStorage[selectedCameraStorageKey] = e.target.hash; + }); + self.selectDefaultWebcam(); self.recreateIntersectionObservers(); }; diff --git a/src/octoprint/templates/tabs/control.jinja2 b/src/octoprint/templates/tabs/control.jinja2 index 7ee865855..222a37896 100644 --- a/src/octoprint/templates/tabs/control.jinja2 +++ b/src/octoprint/templates/tabs/control.jinja2 @@ -1,9 +1,6 @@ {% if enableWebcam %}
- {% set nsContent = namespace(mark_active = True) %} - {% set nsTab = namespace(mark_active = True) %} -
{% for key in templates.webcam.order %} {% set entry, data = templates.webcam.entries[key] %} @@ -11,7 +8,7 @@ {% if "custom_bindings" not in data or data["custom_bindings"] %}{% endif %}
{% try "There was an error with the template {filename} at line number {lineno}: {exception}" %}{% include data.template ignore missing %}{% endtry %} @@ -29,7 +26,7 @@ {% set entry, data = templates.webcam.entries[key] %} {% endfor %}