From 1074bd8b1492e95671a72916f4efd3945c6ce3cc Mon Sep 17 00:00:00 2001 From: Mahmoud Ayesh <141195446+mahmoudhusam@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:39:00 +0300 Subject: [PATCH 1/7] Add context-menu item for generating QR code for the current page (#321) --- src/_locales/en/messages.json | 8 ++++++++ src/background/modules/ContextMenu.js | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 71a1ecd8..b921355f 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -186,6 +186,14 @@ "message": "&QR code from link", "description": "The context menu entry shown for generating QR codes from a selected link with an access key." }, + "contextMenuItemConvertPageURL": { + "message": "Generate QR Code for this Page", + "description": "Context menu item title for generating a QR code for the current page URL." + }, + "contextMenuItemConvertPageURLAccessKey": { + "message": "&Generate QR Code for this Page", + "description": "Context menu item title for generating a QR code for the current page URL with an access key." + }, "contextMenuSaveImageCanvas": { "message": "Save QR code as an image…", "description": "The context menu entry shown for saving PNG images (from a canvas) in the popup." diff --git a/src/background/modules/ContextMenu.js b/src/background/modules/ContextMenu.js index 605d74df..b0726442 100644 --- a/src/background/modules/ContextMenu.js +++ b/src/background/modules/ContextMenu.js @@ -4,6 +4,7 @@ import { createMenu } from "/common/modules/ContextMenu.js"; const CONVERT_TEXT_SELECTION = "qr-convert-text-selection"; const CONVERT_LINK_TEXT_SELECTION = "qr-convert-link-text-selection"; const OPEN_OPTIONS = "qr-open-options"; +const CONVERT_PAGE_URL = "qr-convert-page-url"; const MESSAGE_RESENT_TIMEOUT = 200; // ms const MESSAGE_RESENT_MAX = 9; @@ -55,12 +56,17 @@ function createItems() { contexts: ["link"] }); + const pageMenu = createMenu("contextMenuItemConvertPageURL", { + id: CONVERT_PAGE_URL, + contexts: ["page"] + }); + browser.menus.refresh(); // if listener is set, because items were hidden -> remove it browser.menus.onHidden.removeListener(createItems); - return Promise.all([selectionMenu, linkMenu]); + return Promise.all([selectionMenu, linkMenu, pageMenu]); } /** @@ -88,6 +94,13 @@ function menuClicked(event) { sendQrCodeText(event.linkUrl); }); break; + case CONVERT_PAGE_URL: + browser.browserAction.openPopup().then(() => { + messageResentCount = 0; + // Send the current page URL to the popup + sendQrCodeText(event.pageUrl); + }); + break; case OPEN_OPTIONS: browser.runtime.openOptionsPage(); break; From ba9630f38b34bbaaa67a26b929303a4c8746989d Mon Sep 17 00:00:00 2001 From: Mahmoud Ayesh <141195446+mahmoudhusam@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:40:08 +0300 Subject: [PATCH 2/7] Update src/_locales/en/messages.json Co-authored-by: rugk --- src/_locales/en/messages.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index b921355f..c68521d2 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -187,11 +187,11 @@ "description": "The context menu entry shown for generating QR codes from a selected link with an access key." }, "contextMenuItemConvertPageURL": { - "message": "Generate QR Code for this Page", + "message": "Generate QR code for this page", "description": "Context menu item title for generating a QR code for the current page URL." }, "contextMenuItemConvertPageURLAccessKey": { - "message": "&Generate QR Code for this Page", + "message": "&Generate QR code for this page", "description": "Context menu item title for generating a QR code for the current page URL with an access key." }, "contextMenuSaveImageCanvas": { From 6603f16b41bd5e08871468aee114454eba744a1c Mon Sep 17 00:00:00 2001 From: Mahmoud Ayesh <141195446+mahmoudhusam@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:39:00 +0300 Subject: [PATCH 3/7] Add context-menu item for generating QR code for the current page (#321) --- src/_locales/en/messages.json | 8 ++++++++ src/background/modules/ContextMenu.js | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 71a1ecd8..b921355f 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -186,6 +186,14 @@ "message": "&QR code from link", "description": "The context menu entry shown for generating QR codes from a selected link with an access key." }, + "contextMenuItemConvertPageURL": { + "message": "Generate QR Code for this Page", + "description": "Context menu item title for generating a QR code for the current page URL." + }, + "contextMenuItemConvertPageURLAccessKey": { + "message": "&Generate QR Code for this Page", + "description": "Context menu item title for generating a QR code for the current page URL with an access key." + }, "contextMenuSaveImageCanvas": { "message": "Save QR code as an image…", "description": "The context menu entry shown for saving PNG images (from a canvas) in the popup." diff --git a/src/background/modules/ContextMenu.js b/src/background/modules/ContextMenu.js index 605d74df..b0726442 100644 --- a/src/background/modules/ContextMenu.js +++ b/src/background/modules/ContextMenu.js @@ -4,6 +4,7 @@ import { createMenu } from "/common/modules/ContextMenu.js"; const CONVERT_TEXT_SELECTION = "qr-convert-text-selection"; const CONVERT_LINK_TEXT_SELECTION = "qr-convert-link-text-selection"; const OPEN_OPTIONS = "qr-open-options"; +const CONVERT_PAGE_URL = "qr-convert-page-url"; const MESSAGE_RESENT_TIMEOUT = 200; // ms const MESSAGE_RESENT_MAX = 9; @@ -55,12 +56,17 @@ function createItems() { contexts: ["link"] }); + const pageMenu = createMenu("contextMenuItemConvertPageURL", { + id: CONVERT_PAGE_URL, + contexts: ["page"] + }); + browser.menus.refresh(); // if listener is set, because items were hidden -> remove it browser.menus.onHidden.removeListener(createItems); - return Promise.all([selectionMenu, linkMenu]); + return Promise.all([selectionMenu, linkMenu, pageMenu]); } /** @@ -88,6 +94,13 @@ function menuClicked(event) { sendQrCodeText(event.linkUrl); }); break; + case CONVERT_PAGE_URL: + browser.browserAction.openPopup().then(() => { + messageResentCount = 0; + // Send the current page URL to the popup + sendQrCodeText(event.pageUrl); + }); + break; case OPEN_OPTIONS: browser.runtime.openOptionsPage(); break; From 48c4a1d11dfe0c6876b5e85a5cedeb8247a58305 Mon Sep 17 00:00:00 2001 From: Mahmoud Ayesh <141195446+mahmoudhusam@users.noreply.github.com> Date: Sun, 20 Oct 2024 13:18:01 +0300 Subject: [PATCH 4/7] Fixed context menu feature, added settings checkbox functionality --- src/_locales/en/messages.json | 8 +++++ src/background/modules/ContextMenu.js | 14 +++++++- src/common/modules/data/DefaultSettings.js | 1 + src/options/modules/CustomOptionTriggers.js | 37 ++++++++++++++++++++- src/options/options.html | 9 +++++ 5 files changed, 67 insertions(+), 2 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index b921355f..562051ac 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -250,6 +250,14 @@ "message": "Shows a colored icon instead of the black/white icon in the toolbar.", "description": "This is an option shown in the add-on settings. It describes the optionPopupIconColored setting in more details." }, + "contextMenuEnabled": { + "message": "Enable QR code context menu item", + "description": "Toggle to show or hide the context menu item for generating a QR code for the current page." + }, + "contextMenuEnabledDescr": { + "message": "Enabling this option allows you to create a QR code for the current page using the context menu.", + "description": "Detailed description of the contextMenuEnabled setting." + }, "subtitleQrCodeSize": { "message": "QR code size", diff --git a/src/background/modules/ContextMenu.js b/src/background/modules/ContextMenu.js index b0726442..047d8b3b 100644 --- a/src/background/modules/ContextMenu.js +++ b/src/background/modules/ContextMenu.js @@ -61,6 +61,17 @@ function createItems() { contexts: ["page"] }); + browser.runtime.onMessage.addListener((message) => { + if (message.action === "enableContextMenu") { + browser.menus.update(CONVERT_PAGE_URL, { visible: true }); + console.log("Context menu enabled"); + } else if (message.action === "disableContextMenu") { + browser.menus.update(CONVERT_PAGE_URL, { visible: false }); + console.log("Context menu disabled"); + } + browser.menus.refresh(); + }); + browser.menus.refresh(); // if listener is set, because items were hidden -> remove it @@ -97,7 +108,7 @@ function menuClicked(event) { case CONVERT_PAGE_URL: browser.browserAction.openPopup().then(() => { messageResentCount = 0; - // Send the current page URL to the popup + // Send the current page URL to the popup explicitly to overwrite any setting that may use a different string sendQrCodeText(event.pageUrl); }); break; @@ -132,6 +143,7 @@ function menuShown(info) { browser.menus.remove(CONVERT_TEXT_SELECTION); browser.menus.remove(CONVERT_LINK_TEXT_SELECTION); + browser.menus.remove(CONVERT_PAGE_URL); browser.menus.refresh(); } diff --git a/src/common/modules/data/DefaultSettings.js b/src/common/modules/data/DefaultSettings.js index 03be7613..7db61e98 100644 --- a/src/common/modules/data/DefaultSettings.js +++ b/src/common/modules/data/DefaultSettings.js @@ -17,6 +17,7 @@ const isDarkTheme = window.matchMedia("(prefers-color-scheme: dark)").matches; const defaultSettings = Object.freeze({ debugMode: false, popupIconColored: false, + contextMenuEnabled: true, qrColor: "#0c0c0d", qrBackgroundColor: (isDarkTheme ? "#d7d7db" : "#ffffff"), // dark uses Firefox Photon's grey-30 qrErrorCorrection: "Q", diff --git a/src/options/modules/CustomOptionTriggers.js b/src/options/modules/CustomOptionTriggers.js index a0512a23..52918932 100644 --- a/src/options/modules/CustomOptionTriggers.js +++ b/src/options/modules/CustomOptionTriggers.js @@ -72,6 +72,37 @@ function applyPopupIconColor(optionValue) { IconHandler.changeIconIfColored(optionValue); } +/** + * Adjusts UI based on the state of context menu enabled option. + * + * @function + * @private + * @param {boolean} optionValue + * @returns {void} + */ +function applyContextMenuEnabled(optionValue) { + if (optionValue) { + console.log("Context menu is enabled"); + // Call the logic to enable the context menu + browser.runtime.sendMessage({ action: "enableContextMenu" }); + } else { + console.log("Context menu is disabled"); + // Call the logic to disable the context menu + browser.runtime.sendMessage({ action: "disableContextMenu" }); + } +} + +/** + * Event listener to save the checkbox state and apply it. + */ +document.getElementById('contextMenuEnabled').addEventListener('change', async (event) => { + const isChecked = event.target.checked; + await browser.storage.local.set({ contextMenuEnabled: isChecked }); + + // Apply the context menu based on the checkbox state + applyContextMenuEnabled(isChecked); +}); + /** * Adjust UI if QR code size option is changed. * @@ -254,10 +285,14 @@ export function registerTrigger() { AutomaticSettings.Trigger.registerSave("qrBackgroundColor", applyQrCodeColors); AutomaticSettings.Trigger.registerSave("qrQuietZone", updateQrQuietZoneStatus); + // Register trigger for contextMenuEnabled + AutomaticSettings.Trigger.registerSave("contextMenuEnabled", applyContextMenuEnabled); + AutomaticSettings.Trigger.registerUpdate("contextMenuEnabled", applyContextMenuEnabled); + AutomaticSettings.Trigger.registerUpdate("qrColor", applyQrCodeColors); AutomaticSettings.Trigger.registerUpdate("qrBackgroundColor", applyQrCodeColors); // handle loading of options correctly AutomaticSettings.Trigger.registerBeforeLoad(resetOnBeforeLoad); AutomaticSettings.Trigger.registerAfterLoad(AutomaticSettings.Trigger.RUN_ALL_SAVE_TRIGGER); -} +} \ No newline at end of file diff --git a/src/options/options.html b/src/options/options.html index 3169dce3..c484f18a 100644 --- a/src/options/options.html +++ b/src/options/options.html @@ -64,6 +64,15 @@

Add-on

Shows a colored icon instead of the black/white icon in the toolbar. +
  • +
    + + +
    +
    + Show context menu item to create QR code for the current page. +
    +
  • From 81ba19a33016833b637845a7cb2bccce96002812 Mon Sep 17 00:00:00 2001 From: Mahmoud Ayesh <141195446+mahmoudhusam@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:38:25 +0300 Subject: [PATCH 5/7] Fixes based on feedback: Removed custom option saving, added i18n attributes, improved UX for context menu setting, and moved event listener --- src/_locales/en/messages.json | 12 ++++++------ src/background/modules/ContextMenu.js | 21 ++++++++++----------- src/options/modules/CustomOptionTriggers.js | 11 ----------- src/options/options.html | 4 ++-- 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 6ccf1d8d..2916ba83 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -250,13 +250,13 @@ "message": "Shows a colored icon instead of the black/white icon in the toolbar.", "description": "This is an option shown in the add-on settings. It describes the optionPopupIconColored setting in more details." }, - "contextMenuEnabled": { - "message": "Enable QR code context menu item", - "description": "Toggle to show or hide the context menu item for generating a QR code for the current page." + "optionContextMenuEnabled": { + "message": "Show general QR code generation context menu item", + "description": "This label refers to an option in the add-on settings. It allows users to toggle the visibility of the context menu item for generating a QR code from the current page." }, - "contextMenuEnabledDescr": { - "message": "Enabling this option allows you to create a QR code for the current page using the context menu.", - "description": "Detailed description of the contextMenuEnabled setting." + "optionContextMenuEnabledDescr": { + "message": "Shows a context menu item to create QR code for the current page, in addition to links and text selections.", + "description": "This is the helper text for the context menu toggle option. It explains that enabling this option will show the QR code generation context menu for the current page." }, "subtitleQrCodeSize": { diff --git a/src/background/modules/ContextMenu.js b/src/background/modules/ContextMenu.js index 047d8b3b..f60034e5 100644 --- a/src/background/modules/ContextMenu.js +++ b/src/background/modules/ContextMenu.js @@ -61,17 +61,6 @@ function createItems() { contexts: ["page"] }); - browser.runtime.onMessage.addListener((message) => { - if (message.action === "enableContextMenu") { - browser.menus.update(CONVERT_PAGE_URL, { visible: true }); - console.log("Context menu enabled"); - } else if (message.action === "disableContextMenu") { - browser.menus.update(CONVERT_PAGE_URL, { visible: false }); - console.log("Context menu disabled"); - } - browser.menus.refresh(); - }); - browser.menus.refresh(); // if listener is set, because items were hidden -> remove it @@ -160,5 +149,15 @@ export function init() { return createItems().then(() => { browser.menus.onClicked.addListener(menuClicked); browser.menus.onShown.addListener(menuShown); + browser.runtime.onMessage.addListener((message) => { + if (message.action === "enableContextMenu") { + browser.menus.update(CONVERT_PAGE_URL, { visible: true }); + console.log("Context menu enabled"); + } else if (message.action === "disableContextMenu") { + browser.menus.update(CONVERT_PAGE_URL, { visible: false }); + console.log("Context menu disabled"); + } + browser.menus.refresh(); + }); }); } diff --git a/src/options/modules/CustomOptionTriggers.js b/src/options/modules/CustomOptionTriggers.js index 52918932..f6a8b293 100644 --- a/src/options/modules/CustomOptionTriggers.js +++ b/src/options/modules/CustomOptionTriggers.js @@ -92,17 +92,6 @@ function applyContextMenuEnabled(optionValue) { } } -/** - * Event listener to save the checkbox state and apply it. - */ -document.getElementById('contextMenuEnabled').addEventListener('change', async (event) => { - const isChecked = event.target.checked; - await browser.storage.local.set({ contextMenuEnabled: isChecked }); - - // Apply the context menu based on the checkbox state - applyContextMenuEnabled(isChecked); -}); - /** * Adjust UI if QR code size option is changed. * diff --git a/src/options/options.html b/src/options/options.html index c484f18a..c974b131 100644 --- a/src/options/options.html +++ b/src/options/options.html @@ -67,10 +67,10 @@

    Add-on

  • - +
    - Show context menu item to create QR code for the current page. + Shows a context menu item to create QR code for the current page, in addition to links and text selections.
  • From 0cff370656a1272fedd0fd9695050c637ff7abc6 Mon Sep 17 00:00:00 2001 From: rugk Date: Wed, 23 Oct 2024 16:09:00 +0200 Subject: [PATCH 6/7] Add German translation for common context menu --- src/_locales/de/messages.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/_locales/de/messages.json b/src/_locales/de/messages.json index 49077bda..48907b5b 100644 --- a/src/_locales/de/messages.json +++ b/src/_locales/de/messages.json @@ -186,6 +186,14 @@ "message": "&QR-Code aus Link", "description": "The context menu entry shown for generating QR codes from a selected link with an access key." }, + "contextMenuItemConvertPageURL": { + "message": "Generiere QR-Code für diese Seite", + "description": "Context menu item title for generating a QR code for the current page URL." + }, + "contextMenuItemConvertPageURLAccessKey": { + "message": "&Generiere QR-Code für diese Seite", + "description": "Context menu item title for generating a QR code for the current page URL with an access key." + }, "contextMenuSaveImageCanvas": { "message": "QR-Code als Bild speichern…", "description": "The context menu entry shown for saving SVG images in the popup." @@ -241,6 +249,14 @@ "message": "Zeigt ein farbiges Icon anstatt eines schwarz/weißen Icons in der Toolbar.", "description": "This is an option shown in the add-on settings. It describes the optionPopupIconColored setting in more details." }, + "optionContextMenuEnabled": { + "message": "Zeige allgemeinen QR-Code-Generierungs-Kontextmenü-Eintrag", + "description": "This label refers to an option in the add-on settings. It allows users to toggle the visibility of the context menu item for generating a QR code from the current page." + }, + "optionContextMenuEnabledDescr": { + "message": "Zeigt einen Kontextmenü-Eintrag um QR-Codes für die aktuelle Seite zu erstellen, zusätzlich zu denen für Links und ausgewählten Text.", + "description": "This is the helper text for the context menu toggle option. It explains that enabling this option will show the QR code generation context menu for the current page." + }, "subtitleQrCodeSize": { "message": "QR-Code-Größe", From e8c307d7dd58e4e2cb5091e1b14b7eedd10d1945 Mon Sep 17 00:00:00 2001 From: Mahmoud Ayesh <141195446+mahmoudhusam@users.noreply.github.com> Date: Wed, 23 Oct 2024 18:44:58 +0300 Subject: [PATCH 7/7] Added my name to CONTRIBUTORS.md --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 9d4a814e..e1db26b3 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -16,6 +16,7 @@ - Metta Ong ([@ongspxm](https://github.com/ongspxm)) - Michael Corwin ([@mcorwin22](https://github.com/mcorwin22)) - Pradyumna Mahajan ([@pradyumnamahajan](https://github.com/pradyumnamahajan)) +- Mahmoud Ayesh ([@mahmoudhusam](https://github.com/mahmoudhusam)) ## Translators