From 281599ecd9a280ec4ae93930ab27722b6aea142d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 6 Feb 2023 12:14:58 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20Add=20webcam=20compat=20layer=20?= =?UTF-8?q?to=20settings=20view=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Should prevent issues on the release of 1.9.0 with plugins that have not yet been adapted to the new webcam subsystem. --- .../static/js/app/viewmodels/settings.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index 26fe42015..3276c5b0a 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -392,6 +392,18 @@ $(function () { } }); + self.webcamCompat = { + webcam_streamUrl: "streamUrl", + webcam_streamRatio: "streamRatio", + webcam_streamTimeout: "streamTimeout", + webcam_streamWebrtcIceServers: "webrtcIceServers", + webcam_snapshotUrl: "snapshotUrl", + webcam_flipH: "flipH", + webcam_flipV: "flipV", + webcam_rotate90: "rotate90", + webcam_cacheBuster: "cacheBuster" + }; + self.addTemperatureProfile = function () { self.temperature_profiles.push({ name: "New", @@ -1161,6 +1173,31 @@ $(function () { } }; + // set up webcam compat layer if not yet done + _.each(self.webcamCompat, (mapped, key) => { + if (self.settings.hasOwnProperty(key)) return; + if (!self.settings.webcam.hasOwnProperty(mapped)) return; + const message = + "Please use the webcam system introduced with 1.9.0, the " + + key + + " config setting is deprecated and will be removed in a future release. Stacktrace:"; + self[key] = ko.pureComputed({ + read: () => { + const exc = new Error(); + log.warn(message, exc.stack || exc.stacktrace || ""); + + return self.settings.webcam[mapped](); + }, + write: (value) => { + const exc = new Error(); + log.warn(message, exc.stack || exc.stacktrace || ""); + + self.settings.webcam[mapped](value); + }, + owner: self + }); + }); + var mapToObservables = function (data, mapping, local, keyPrefix) { if (!_.isPlainObject(data)) { return; @@ -1178,6 +1215,11 @@ $(function () { return; } + if (self.webcamCompat.hasOwnProperty(observable)) { + // webcam compat layer, skip + return; + } + var haveLocalVersion = local && local.hasOwnProperty(key); if (