diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json
index 7731fdb..ea0ffcd 100644
--- a/src/_locales/en/messages.json
+++ b/src/_locales/en/messages.json
@@ -108,6 +108,10 @@
"message": "Use contrasting color",
"description": "The text of a button that sets a new color with a sufficient contrast."
},
+ "qrCodeSizeTooLargeWarning": {
+ "message": "The selected QR code size exceeds the available display space. The displayed QR code has been resized to fit. ",
+ "description": "The message shown when the requested QR code size is too large to display and has been automatically scaled down to fit."
+ },
// tips
"tipYouLikeAddon": {
diff --git a/src/popup/modules/UserInterface.js b/src/popup/modules/UserInterface.js
index 6da4d66..d0313b4 100644
--- a/src/popup/modules/UserInterface.js
+++ b/src/popup/modules/UserInterface.js
@@ -25,11 +25,12 @@ import {createMenu} from "/common/modules/ContextMenu.js";
const TOP_SCROLL_TIMEOUT = 20; // ms
const QR_CODE_REFRESH_TIMEOUT = 200; // ms
-const QR_CODE_CONTAINER_MARGIN = 40; // px
+export const QR_CODE_CONTAINER_MARGIN = 40; // px
const QR_CODE_SIZE_SNAP = 5; // px
const QR_CODE_SIZE_DECREASE_SNAP = 2; // px
const WINDOW_MINIMUM_HEIGHT = 250; // px
const THROTTLE_SIZE_SAVING_FOR_REMEMBER = 500; // ms
+export const MAX_WINDOW_HEIGHT = 600;
const CONTEXT_MENU_SAVE_IMAGE_CANVAS = "save-image-canvas";
const CONTEXT_MENU_SAVE_IMAGE_SVG = "save-image-svg";
@@ -47,6 +48,8 @@ const qrCodeText = document.getElementById("qrcodetext");
let resizeMutationObserver;
let placeholderShown = true;
+let sizeWarningShown = false;
+let firstResize = true; // check if initial resize is needed
// default/last size
let qrLastSize = 200;
@@ -267,7 +270,29 @@ function saveQrCodeTextSize() {
* @returns {void}
*/
function resizeElements() {
- const newQrCodeSize = Math.min(qrCodeContainer.offsetHeight, qrCodeContainer.offsetWidth) - QR_CODE_CONTAINER_MARGIN;
+
+ // if a size warning is shown upon resize, hide it
+ if (sizeWarningShown) {
+ CommonMessages.hideWarning();
+ }
+
+ let newQrCodeSize = Math.min(qrCodeContainer.offsetHeight, qrCodeContainer.offsetWidth) - QR_CODE_CONTAINER_MARGIN;
+
+ // the warning is shown only on desktop
+ if (!navigator.userAgent.includes("Mobile")) {
+ // if initial resize is needed, compute maximum allowed qr code size
+ if (firstResize) {
+ firstResize = false;
+ newQrCodeSize = Math.min(qrLastSize, MAX_WINDOW_HEIGHT - qrCodeText.offsetHeight - QR_CODE_CONTAINER_MARGIN);
+
+ // if the fixed qr code size is larger than the maximum allowed qr code size, add warning
+ if (newQrCodeSize < qrLastSize) {
+ sizeWarningShown = true;
+ CommonMessages.showWarning("qrCodeSizeTooLargeWarning", true);
+ }
+ }
+ }
+
const qrSizeDiff = newQrCodeSize - qrLastSize;
// rezizing at small window heights (e.g. when popup is being constructed)
@@ -641,6 +666,9 @@ export function init() {
console.error("too small size", window.innerHeight, "should be at least: ", minimalSize);
}
}
+
+ // initial resize to fit centering issue of QR code
+ resizeElements();
});
const initQrTypespecificSettings = createContextMenu();
diff --git a/src/popup/qrcode.html b/src/popup/qrcode.html
index b8f8050..6c0e028 100644
--- a/src/popup/qrcode.html
+++ b/src/popup/qrcode.html
@@ -41,6 +41,10 @@
+