-
Notifications
You must be signed in to change notification settings - Fork 127
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
Conversation
Co-authored-by: rugk <[email protected]>
There was a problem hiding this 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:
- First of all, would you have a screenshot or even screencast to show (how) it works?
- Secondly, I see you may need to add removing that menu entry to the
menuShown
function like the others? I am not sure why, but maybe because it is re-rendered… and may not be shown every time? I am unsure, and unfortunately the JSDoc is also not helpful there (blame on me, but feel free to improve it) - Generally, as explained in the issue before (Add context-menu item for generating a QR code for _the current page_ #321 (comment)) the feature needs to be configurable. That is as far as I see still missing. See Add settings checkbox for removing context menu item #157 (comment) and FYI for some guides/pointers on how to introduce such a setting.
// Send the current page URL to the popup | ||
sendQrCodeText(event.pageUrl); |
There was a problem hiding this comment.
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:
// 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); |
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). Thanks again for your support. |
There was a problem hiding this 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 }); |
There was a problem hiding this comment.
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"> |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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?
…ributes, improved UX for context menu setting, and moved event listener
Hi @rugk, Thanks for the detailed feedback! I've made the following adjustments based on your suggestions:
Looking forward to your thoughts! |
There was a problem hiding this 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.
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. 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 |
i added my name to to the CONTRIBUTORS.md, but i did not know where to add a changelog entry for my code : Added
is this good and where should i add it? |
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) Feel free to add it there (in a new PR), but I guess I merge it now already. |
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.) |
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.