Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context-menu item for generating QR code for the current page (#321) #336

Merged
merged 10 commits into from
Oct 24, 2024

Conversation

mahmoudhusam
Copy link
Contributor

This PR adds a context-menu item to generate a QR code for the current page URL. The functionality is implemented in the ContextMenu.js module, and a new message string was added to messages.json for localization.
Resolves issue #321.

src/background/modules/ContextMenu.js Dismissed Show dismissed Hide dismissed
src/background/modules/ContextMenu.js Dismissed Show dismissed Hide dismissed
src/_locales/en/messages.json Outdated Show resolved Hide resolved
Copy link
Owner

@rugk rugk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mahmoudhusam,
first of all, thanks for your first contribution to this project! 🎉 👍 🏅
I hope you'll like this project and enjoy hacking on it… 😃

It generally looks good, but I have some pointers to change:

Comment on lines 100 to 101
// Send the current page URL to the popup
sendQrCodeText(event.pageUrl);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK/IIRC you don't need to do that explicitly, as it is the default behaviour. Though settings can obviously change that and if you e.g. always use the text selection then you have two menu entries that would do the same, so IMHO, yeah… makes sense and this is fine.

Could you just test this use case? Aka enable the setting to use the text-selection by default and then use this menu entry? Does it work as expected?

Also maybe adding this here as an explanation seems good:

Suggested change
// Send the current page URL to the popup
sendQrCodeText(event.pageUrl);
// Send the current page URL to the popup explicitly to overwrite any setting that may use a different string
sendQrCodeText(event.pageUrl);

@mahmoudhusam
Copy link
Contributor Author

Hi @rugk,

Thank you so much for your guidance and for helping me through my first contribution to open-source! I've learned a lot from this project, and your feedback has been incredibly valuable.

I've implemented the requested changes:

Added a screencast demonstrating the new feature in action (attached below).
Please let me know if there's anything else you'd like me to adjust. I'm more than happy to make further improvements!

Thanks again for your support.

contextMenuItemConvertPageURL
contextMenuEnabled

Copy link
Owner

@rugk rugk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Did you test it and everything worked?

I've left some comments for spots, where things need to be improved, but we're close though…

*/
document.getElementById('contextMenuEnabled').addEventListener('change', async (event) => {
const isChecked = event.target.checked;
await browser.storage.local.set({ contextMenuEnabled: isChecked });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't handle option saving manually.

Also, it's already saved by the library, so no need to save it again… AutomaticSettings.Trigger below handles it all, so this whole custom handling/element registration should be removed…

@@ -64,6 +64,15 @@ <h1 data-i18n="__MSG_titleGeneral__">Add-on</h1>
<span class="helper-text" data-i18n="__MSG_optionPopupIconColoredDescr__">Shows a colored icon instead of the black/white icon in the toolbar.</span>
</div>
</li>
<li>
<div class="line">
<input class="setting save-on-change" type="checkbox" id="contextMenuEnabled" name="contextMenuEnabled">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Could you add the required i18n attributes to enable localisation? Aka internationalize this part here?

Also provide the translation string in the message.json file, so people can translate it. It is enough to provide the English translation, of course, so you can just copy and paste the string from here.
This ensures, that text snippet is ready for translation and can be localized.

For more information, please see the MDN guide on how to localize WebExtensions and our internationalization (i18n) guide.

Also cf the rest of the options HTML of course.

@@ -61,6 +61,17 @@ function createItems() {
contexts: ["page"]
});

browser.runtime.onMessage.addListener((message) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, generally thougj let's move that into the init functions below, don't we? Otherwise it could get re-registered and triggered multiple times when createItems() is called?

src/options/options.html Outdated Show resolved Hide resolved
…ributes, improved UX for context menu setting, and moved event listener
@mahmoudhusam
Copy link
Contributor Author

Hi @rugk,

Thanks for the detailed feedback! I've made the following adjustments based on your suggestions:

  • Removed the manual saving of the option in CustomOptionTriggers.js, as it’s already handled by AutomaticSettings.Trigger.
  • Added the necessary i18n attributes for localization in options.html and updated messages.json with the corresponding strings.
  • Moved the browser.runtime.onMessage.addListener to the init function in ContextMenu.js to prevent multiple registrations.
  • Clarified the label and helper text for the context menu setting to avoid confusion and improve UX.

Looking forward to your thoughts!

Copy link
Owner

@rugk rugk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Code-wise, this looks like it should work.

@rugk
Copy link
Owner

rugk commented Oct 23, 2024

Okay, tried it out and pushed the German translations.

Also noticed we could change the behavior to also show this entry when some other context menu item is shown, so the user could decide which one to use.

Like e.g. if you select text:
grafik

…or click a link:
grafik

…or even do both:
grafik

The issue is, Firefox automatically makes it a sub-context menu as you can see – and it does not look as nice, IMHO.

Code-wise, the change is simple, but changes a lot:

diff --git a/src/background/modules/ContextMenu.js b/src/background/modules/ContextMenu.js
index f60034e..910560a 100644
--- a/src/background/modules/ContextMenu.js
+++ b/src/background/modules/ContextMenu.js
@@ -58,7 +58,7 @@ function createItems() {
 
     const pageMenu = createMenu("contextMenuItemConvertPageURL", {
         id: CONVERT_PAGE_URL,
-        contexts: ["page"]
+        contexts: ["page", "link", "selection"]
     });
 
     browser.menus.refresh();

I've tested it and it would work, but by testing it, I think, we better leave it as it is, because then only one context menu item is shown when users interact with the extension.

Also, BTW, I initially thought this feature (common context menu) should be opt-in, but after seeing it and knowing Chrome also enables it by default, I guess we can follow the route.

One thing missing might just be: Add a changelog entry and add yourself to the CONTRIBUTORS.md BTW, @mahmoudhusam. Then we're done!

@mahmoudhusam
Copy link
Contributor Author

i added my name to to the CONTRIBUTORS.md, but i did not know where to add a changelog entry for my code :

Added

  • Context Menu Item for QR Code Generation: Implemented a new feature that allows users to generate a QR code for the current page via a context menu item. This feature enhances user experience by providing quick access to QR code generation without navigating through the main UI.

  • Settings Option to Enable/Disable Context Menu Item: Added a settings option that enables users to toggle the context menu item for QR code generation on or off. This provides users with greater control over their interface and helps customize their experience based on their preferences.

is this good and where should i add it?

@rugk
Copy link
Owner

rugk commented Oct 24, 2024

Thanks yeah, and BTW you don't need to repeat what you've added (and I hope this is no AI summary)

And yeah, that file was not there yet, the Changelog can be added here: https://github.com/rugk/offline-qr-code/blob/master/assets/texts/en/Changelog/next.md (Just like the other changelogs)
Edit: Ah in case that should be the changelog it is somewhat verbose, a shorter one-liner is fine. As said, see how the other changelogs are written.

Feel free to add it there (in a new PR), but I guess I merge it now already.

@rugk rugk merged commit 5558b0e into rugk:master Oct 24, 2024
9 checks passed
@rugk rugk linked an issue Oct 31, 2024 that may be closed by this pull request
@rugk
Copy link
Owner

rugk commented Oct 31, 2024

And FYI next time you can (automatically) let issues close when a PR is merged by adding some "magic" text to your PR body. (Manually linked it now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add context-menu item for generating a QR code for _the current page_
2 participants