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 button_url[] and hypertext element to allow mods to open web pages #13825

Merged
merged 20 commits into from Mar 24, 2024

Conversation

rubenwardy
Copy link
Member

@rubenwardy rubenwardy commented Sep 20, 2023

Fixes #12500

This adds a new type of button and a hypertext attribute to allow opening URLs in a web browser. A button is used to require user interaction before opening URLs.

A confirmation dialog is shown, to allow the user to see the URL. Unfortunately, this confirmation dialog has to be implemented using raw Irrlicht GUI for security reasons, so cannot be themed by games and looks a bit odd compared to the rest of the GUI. This should be improved in the future

image

To do

This PR is Ready for Review

  • Clean up parseButtonURL duplication
  • Fix line wrapping / scrolling to see entire URL in box
  • Highlight domain name
  • Add hypertext tag (maybe for a next PR?)
  • Fix CURLU_PUNYCODE requiring Curl 7.88
  • Improve dialog message (suggestions welcome)

For future PRs:

  • Add ability to 'trust' domain names

How to test

Click the red button in the Styled tab of /test_formspec in devtest

Click the URL link in the hypertext tab

@rubenwardy rubenwardy added @ Script API Feature ✨ PRs that add or enhance a feature Formspec labels Sep 20, 2023
@rubenwardy rubenwardy marked this pull request as draft September 20, 2023 17:57
@rubenwardy rubenwardy added the WIP The PR is still being worked on by its author and not ready yet. label Sep 20, 2023
@Desour
Copy link
Member

Desour commented Sep 20, 2023

It would be nice if the editbox was editable, so that user can remove parts of the url before opening it.

@oong819
Copy link
Contributor

oong819 commented Sep 21, 2023

Δяε tΗeгe aпythΙng тo ρяevеnτ homοgrаph?

еχаmрle.org

@rubenwardy
Copy link
Member Author

Not yet. I'd like to use a font that distinguishes a lot of things differently (ie I vs l) and I'd also like to color letters based on character class (which would highlight homographs)

@rubenwardy rubenwardy added the Concept approved Approved by a core dev: PRs welcomed! label Jan 14, 2024
@Zughy Zughy added Supported by core dev Not on the roadmap, yet some core dev decided to take care of this PR and removed Concept approved Approved by a core dev: PRs welcomed! labels Jan 21, 2024
@rubenwardy
Copy link
Member Author

rubenwardy commented Feb 17, 2024

The dialog now uses a mono font and colorizes the URL. Non alphanumeric characters are shown as red, for example the Cyrillic small letter a here:

image

src/gui/guiOpenURL.cpp Outdated Show resolved Hide resolved
src/gui/guiOpenURL.cpp Outdated Show resolved Hide resolved
@rubenwardy
Copy link
Member Author

One option would be to show the punycode instead:

Screenshot_2024-02-17_18-04

If the URL doesn't contain unsafe characters, it appears as normal:

Untitled

@appgurueu
Copy link
Contributor

I support showing punycode, especially as I don't trust our Unicode handling enough to make sure that Unicode characters would be properly discernible.

I would also be fine with only allowing ASCII for a first implementation. URLs are largely ASCII-encodable, and if not, you can still have an ASCII-only URL redirect to the target URL.

@rubenwardy
Copy link
Member Author

rubenwardy commented Feb 17, 2024

Done. Also added break word line wrapping (need to fix follow on line colors)

image

@rubenwardy rubenwardy changed the title Add button_url[] to allow mods to open web pages Add button_url[] and hypertext element to allow mods to open web pages Feb 17, 2024
@rubenwardy rubenwardy marked this pull request as ready for review February 17, 2024 20:07
@rubenwardy rubenwardy removed the WIP The PR is still being worked on by its author and not ready yet. label Feb 17, 2024
@rubenwardy
Copy link
Member Author

You can now open links from hypertext:

<action name=open url=https://example.com/?a=b#c>open URL</action>

src/gui/guiFormSpecMenu.cpp Show resolved Hide resolved
src/util/colorize.cpp Outdated Show resolved Hide resolved
src/util/colorize.h Show resolved Hide resolved
src/util/colorize.cpp Outdated Show resolved Hide resolved
src/util/colorize.cpp Outdated Show resolved Hide resolved
src/util/colorize.cpp Outdated Show resolved Hide resolved
src/unittest/test_utilities.cpp Outdated Show resolved Hide resolved
src/util/colorize.cpp Outdated Show resolved Hide resolved
src/util/colorize.cpp Outdated Show resolved Hide resolved
@rubenwardy rubenwardy requested a review from sfan5 March 3, 2024 15:18
Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

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

code complaints only :)

games/devtest/mods/testformspec/formspec.lua Outdated Show resolved Hide resolved
games/devtest/mods/testformspec/formspec.lua Show resolved Hide resolved
src/client/game.cpp Outdated Show resolved Hide resolved
src/gui/guiHyperText.cpp Show resolved Hide resolved
src/gui/guiOpenURL.cpp Outdated Show resolved Hide resolved
src/util/colorize.cpp Outdated Show resolved Hide resolved
src/util/colorize.cpp Outdated Show resolved Hide resolved
src/util/colorize.cpp Outdated Show resolved Hide resolved
src/util/colorize.cpp Outdated Show resolved Hide resolved
src/util/colorize.cpp Outdated Show resolved Hide resolved
@sfan5 sfan5 added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Mar 20, 2024
@sfan5 sfan5 self-assigned this Mar 20, 2024
@rubenwardy rubenwardy removed the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Mar 23, 2024
@rubenwardy
Copy link
Member Author

image

image

src/gui/guiHyperText.h Outdated Show resolved Hide resolved
@sfan5 sfan5 self-requested a review March 23, 2024 20:02
Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

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

works

@rubenwardy rubenwardy merged commit 24cc33e into minetest:master Mar 24, 2024
15 checks passed
@rubenwardy rubenwardy deleted the urlbutton branch March 24, 2024 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature ✨ PRs that add or enhance a feature Formspec One approval ✅ ◻️ @ Script API Supported by core dev Not on the roadmap, yet some core dev decided to take care of this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow formspecs to open URLs
6 participants