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
Use gtk_show_uri_on_window() in utils_open_browser() by default #3178
Conversation
|
Yes, I've used goto. What's your point again? |
Why? you jump to a one liner followed by return, whats the point of that? It saves nothing material in code and makes it harder to follow. |
No, it's not that simple. The return is only if Please suggest a comparably concise way to accomplish that, otherwise we have no rule that forbids goto. |
I'm not a "never ever use goto nowhere nohow" person, I am just bemused that you did it that way which seems convoluted to me. Why not just copy lines 93 94 in place of line 109, then its clearly inside the loop instead of jumping out the loop and re-entering it? [Edit: line numbers refer to the changed version of the file] |
I think I found another solution, also without goto. Please check agian. |
Ok fine. My only suggestion is that the last dialog line should now say "Please correct it or enter another one, or remove it to use your system default.". |
I'm hesitant because it invalidates all the existing translations. Do you still think it's a good idea? |
The next release is going to have many invalidated translations anyway, I wouldn't have thought one more would hurt. |
Alright, hope it's fine now. |
LGTM |
@kugel- Just a question thats only tangentially related to this PR, but you mentioned it in the initial commit message, if a flatpack can't execute random commands, how does an IDE that is compiling and running all sorts of weird code work as a flatpack? |
Well, actually the sandbox provides a wrapper command to run commands on the host and I'm going to use that for Geany, so not much changes to non-flatpack builds (I declare the permission to do that in the flatpak manifest). That would work for the browser as well but this patch is a good idea anyway (should clarify the commit message) since the current default doesn't work for lots of people. But I also looked at what Gnome Builder does, and that doesn't use the escape command. Instead it doesn't use the "Gnome Runtime" but the "Gnome SDK" as runtime. The SDK includes make, gcc and all that stuff. But Gnome Builder is still constrained to what's in the sandbox. |
And the truth is that I found the escape command only after making this patch, hence the commit message. |
I agree that this is a good idea anyway, have continued the flatpack discussion at #3199 |
According to the docs, And it doesn't work on Windows (who is actually surprised?). It returns
GError message: No idea what this means and why the helper program could not be executed :(. Btw, this is loosely related to #2444. |
Hmmm, well our Glade file targets GTK 3.20 and I think there are other things needing later GTKs even though both Autotools and Meson just check for 3.0 and the Mingw CI passes this PR using GTK 3.8 (AFAICT). So I'm confused what GTK version we really need. |
I've edited my previous post and added a link to the docs which mention 3.22 as requirement. The Mingw CI with GTK 3.8 passes only by accident in this regard because this PR's changes are About the rest of the version confusion, I'm lost as well. I don't know how serious is the Glade file requirement is. |
So how to proceed with the version requirement? I think it would best to codify the 3.22 requirement in configure.ac but that would break the mingw ci. I wonder if it would make sense to create a new bundle based on the msys2 packages and use that for CI. What do you think? |
Apart from the version constraint chaos, before merging this we need to fix the Windows problem. As mentioned ealier in this PR, it does NOT work on Windows and in the current state it will break the behavior for Windows users.
I'm actually on replacing the current Mingw CI builds by a more recent approach using MSYS2 packages: https://github.com/eht16/geany-plugins/blob/ci_add_windows_build/.github/workflows/mingw-w64.yaml I hope I can finish this in a reasonable time frame, then GTK 3.22 would be no problem for the CI. |
Huh? Windows should not change, it's still ifdef'd and uses |
@eht16 ping |
@eht16 ping |
Sorry, I was very unclear in my post :(. I assumed the TODO comment in the Windows code branch was meant to use the new code also on Windows and remove the previous code. This would be nice but won't work as Now, that we checked the new code won't work on Windows, we can happily merge this PR as is, maybe just remove the TODO comment in the Windows code branch. |
898bf04
to
602624a
Compare
@eht16 still unresolved is the (new) requirement for GTK 3.22. FWIW, we can probably formally require the 4-year-old 3.24 which is also the last GTK3 release. It's available in MSYS2 but our windows releases and mingw CI builds still use that ancient version 3.8 isn't it? |
Agree, 3.24 is in Ubuntu 20.04 LTS which is the oldest still supported. |
I agree to require GTK 3.24. The Windows releases use up2date versions of the packages, I usually perform a full "pacman -Syu" in release preparation. |
I'm hesitant to break the CI as that affects not only this PR but all future PRs for other contributors. I would prefer if we (you) could get the CI prepared beforehand. |
Alright, will do. |
Ok, we have geany/geany-plugins#1201 for Geany-Plugins and geany/infrastructure#7 for the necessary supporting scripts. So, feedback on the above PRs is welcome to get them ready to land soon. |
602624a
to
5886331
Compare
Instead of requiring the user to specify a browser just try to use the system default browser through gtk_show_uri_on_window(). This is done when tool_prefs.browser_cmd is empty which is also the new default. This aligns with windows where we do this already. Though we're bypassing tool_prefs.browser_cmd there entirely, while on non-Windows we still honor tool_prefs.browser_cmd when it's set. This is primarily useful for flatpak support where we cannot just execute arbitrary commands on the host (unless using flatpak-spawn). Also, firefox is arguably a bad default these days, given the declined market share.
5886331
to
f1d8abc
Compare
@eht16 The mingw-w64 CI seems to recreate the Docker image from scratch. You implemented a cache didn't you? |
I noticed that the prebuilt Docker image cannot be pulled from the registry and so it is rebuilt on each CI run. I will change the image visibility to public so that everyone can pull it from the registry. I hesitated to do this because once it is public it cannot be deleted any longer. But it is probably OK to do it now, then also PRs can use the prebuilt image. |
/* Uses the user's default browser akin to xdg-open (in flatpak through a portal) */ | ||
if (EMPTY(tool_prefs.browser_cmd)) | ||
{ | ||
if (gtk_show_uri_on_window(GTK_WINDOW(main_widgets.window), uri, GDK_CURRENT_TIME, NULL)) |
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.
If we do care about pre-3.22 GTK, it'd be easy enough to do something like that:
#if GTK_CHECK_VERSION(3, 22, 0)
if (gtk_show_uri_on_window(GTK_WINDOW(main_widgets.window), uri, GDK_CURRENT_TIME, NULL))
#else
if (gtk_show_uri(gtk_widget_get_screen(main_widgets.window), uri, GDK_CURRENT_TIME, NULL))
#endif
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.
But we don't
/* Uses the user's default browser akin to xdg-open (in flatpak through a portal) */ | ||
if (EMPTY(tool_prefs.browser_cmd)) | ||
{ | ||
if (gtk_show_uri_on_window(GTK_WINDOW(main_widgets.window), uri, GDK_CURRENT_TIME, NULL)) |
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.
Just be aware of one thing: gtk_show_uri*()
will happily open a lot more URIs than what the web browser might support. It basically can open any URI, be it http:
, mailto:
or my-custom-scheme:
. It's nice and all, but some suggest that it should be handled with care not to open random programs using random schemes.
Admittedly, there's two things going for us here:
- we're not a chat app or such, we don't present mangled untrusted URIs
- all internal URIs are safe and likely (?) to open in the browser (
https:
,file:
-- need to check that last one though)
But we cannot know what plugins might do.
Though we should check how are file:
URIs handled. We use that in help, and when using the builtin build exec command.
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.
we're not a chat app or such, we don't present mangled untrusted URIs
Its worse than that!!!! If the build command is "builtin" utils_open_browser()
is used to open stuff I wrote 😁
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.
Should I change the patch or was this just a "beware!" remark?
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.
That was just a "beware!" remark, but it'd be nice to check what happens with file://
URIs we might have to local help
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.
Seems we already feed file:// URIs to the function, e.g. for file:///usr/local/share/doc/geany/html/index.html
. So at least file://
must be supported, although without the change we explicitly opened the configured browser, and now we rely on GTK do find the right "browser".
I hesitate to limit the inputs the function accepts. Webdevelopment plugins may want this function to open arbitrary stuff in the browser.
If anything, we might limit to https://
, http://
and file://
but then we might exclude fancy webapps that some plugins could use (they could use gtk_show_uri_on_window()
directly but lets help them to work on windows as well).
And then, on Windows we also do a generic open
, the browser_cmd
configuration is not a thing there.
Long story shot: I leave this as-is until problems arise
Would anyone mind formally approving the current patch? |
Tested and works fine. |
Instead of requiring the user to specify a browser just try to
use the system default browser through gtk_show_uri_on_window().
This is done when tool_prefs.browser_cmd is empty which is
also the new default.
This aligns with windows where we do this already. Though we're
bypassing tool_prefs.browser_cmd there entirely, while on non-Windows
we still honor tool_prefs.browser_cmd when it's set.
This is primarily useful for flatpak support where we cannot just
execute arbitrary commands on the host (unless using flatpak-spawn).
Also, firefox is arguably a bad default these days, given the
declined marked share.