sonnyp / Junction

Application/browser chooser
https://flathub.org/apps/re.sonny.Junction
GNU General Public License v3.0
457 stars 29 forks source link

Fix recomended applications in ViewAllButton dialog #67

Closed davinov closed 2 years ago

davinov commented 2 years ago

Having a lot of browsers, I was frustrated a bit by the limit of 4 introduced recently. However, not a lot of people (except web developers :p) do have that many, so it seems reasonable to keep that limit. I then wanted to use the [...] button (ViewAllButton), but I became more frustrated, as keyboard search was not functioning properly. I noticed that this was the Gtk Widget AppChooserDialog, and that it usually suggest relevant apps on top. But it was not the case when opening URIs :'(

The problem seems to be that AppChooserDialog doesn't suggest recommended apps for dummy files (such as the one passed when junction is called with an URI). So I tried passing the content_type instead, and I saw the recommended apps appear :tada:

Before: Screenshot from 2022-03-14 18-27-51

After: Screenshot from 2022-03-14 18-25-39

Note: I would have even preferred to have a if branch in case we do call Junction with a real file, but I haven't found a way to check if the file is a "DummyFile" or a regular one. (It's one of my first contributions to a Gjs app) So if you know how I could do that, I'd be happy to improve this PR with it :)

Other note: Reading the source, I see that the AppChooserDialog dialog uses a AppChooserWidget, which needs a content_type to be initialized (https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gtk/gtkappchooserdialog.c#L318). This content_type is deduced from the file by g_file_info_get_content_type (https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gtk/gtkappchooserdialog.c#L362), which read the attribute G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE of the File object (https://gitlab.gnome.org/GNOME/glib/-/blob/main/gio/gfileinfo.c#L2230). So the best fix could be to be able to set this attribute for the dummy file (created by Gio.File.new_from_uri). However, after following its source down this the get_file_from_uri_internal (https://gitlab.gnome.org/GNOME/glib/-/blob/main/gio/gvfs.c#L196), it's seems to be another level of complexity (could be done by setting something like x-scheme-handler/<the scheme parsed from the URL>? ...well, maybe thus quick fix is enough time spent on this issue :p).

davinov commented 2 years ago

I almost forgot: thanks for creating this very useful app! :pray:

sonnyp commented 2 years ago

FYI, to better support mobile Junction will probably move to a vertical layout in the future, in which case it will show more than 4 options.