diff --git a/run/input/UPSTREAM_COMMIT b/run/input/UPSTREAM_COMMIT index 3200be2..0e2ab86 100644 --- a/run/input/UPSTREAM_COMMIT +++ b/run/input/UPSTREAM_COMMIT @@ -1 +1 @@ -df978ccebf3bef0d72ac2a03c08f7d2f9a230f87 +504ece74ae6cd2b5b033c540bb2e1f1910c829d5 diff --git a/run/input/core/app/z2ui5/webapp/cc/CameraPicture.js b/run/input/core/app/z2ui5/webapp/cc/CameraPicture.js index 5297f64..1b34c3b 100644 --- a/run/input/core/app/z2ui5/webapp/cc/CameraPicture.js +++ b/run/input/core/app/z2ui5/webapp/cc/CameraPicture.js @@ -3,10 +3,11 @@ sap.ui.define( "sap/ui/core/Control", "sap/m/Dialog", "sap/m/Button", + "sap/m/Text", "sap/ui/core/HTML", "z2ui5/core/Lib", ], - (Control, Dialog, Button, HTML, Lib) => { + (Control, Dialog, Button, Text, HTML, Lib) => { "use strict"; // Camera button: opens a dialog with the live camera stream, captures // a photo on demand and hands it to the backend as a base64 JPEG in @@ -47,18 +48,28 @@ sap.ui.define( }, }, + // Returns true when a photo was taken, false when it could not be (so + // the caller can keep the dialog open and let the status line explain). capture() { const video = document.getElementById(`${this.getId()}-video`); const canvas = document.getElementById(`${this.getId()}-canvas`); - if (!video || !canvas) return; + if (!video || !canvas) return false; const videoWidth = video.videoWidth; const videoHeight = video.videoHeight; + // The camera may not have delivered a frame yet (Capture pressed too + // early, or the stream failed): videoWidth/Height are 0, which would + // make the canvas 0-sized and drawImage() throw an InvalidStateError. + if (!videoWidth || !videoHeight) { + this._setStatus("Camera not ready yet - no frame captured."); + Lib.logError("CameraPicture: camera not ready, no frame to capture"); + return false; + } canvas.width = videoWidth; canvas.height = videoHeight; const ctx = canvas.getContext("2d", _CTX_2D_OPTS); - if (!ctx) return; + if (!ctx) return false; ctx.drawImage(video, 0, 0, videoWidth, videoHeight); // Full-resolution JPEG (quality 0.85) for the value, plus a small @@ -67,8 +78,9 @@ sap.ui.define( try { resultb64 = canvas.toDataURL("image/jpeg", 0.85); } catch (e) { + this._setStatus("Could not read the captured image."); Lib.logError("CameraPicture: canvas toDataURL failed", e); - return; + return false; } const thumbH = videoWidth @@ -87,11 +99,12 @@ sap.ui.define( Lib.logError("CameraPicture: thumb toDataURL failed", e); } - if (Lib.isDestroyed(this)) return; + if (Lib.isDestroyed(this)) return false; this.setProperty("value", resultb64); this.setProperty("thumbnail", thumbB64); this.fireOnPhoto({ photo: resultb64 }); this._stopCamera(); + return true; }, _stopCamera() { @@ -107,6 +120,11 @@ sap.ui.define( onPicture() { if (this._oScanDialog?.isOpen()) return; if (!this._oScanDialog) { + // Visible status line inside the dialog so the user is told what is + // happening (starting, ready, or why the camera stays black). + this._oStatus = new Text().addStyleClass( + "sapUiSmallMarginBegin sapUiSmallMarginTop", + ); this._oScanDialog = new Dialog({ title: "Device Photo Function", contentWidth: "640px", @@ -116,15 +134,21 @@ sap.ui.define( stretch: true, afterClose: () => this._stopCamera(), content: [ + this._oStatus, new HTML({ id: `${this.getId()}PictureContainer`, - content: `