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

Relocate inode/directory association; use Files context menu #857

Closed
wants to merge 22 commits into from

Conversation

quequotion
Copy link

@quequotion quequotion commented Aug 9, 2020

Fixes #856 .

Don't interfere with Files' ownership of inode/directory, use its context menu for this task (opening folders in various applications, like Code).

Plank's Trash can is not the only thing that unexpectedly opens in Code. I've tested a few other applications, such as Transmission, which opens a directory when a user attempts to open an incomplete download.

The problem appears to be that update-desktop-database lists associated .desktop shortcuts for a particular mimetype in alphanumerical order by their filenames in mimeinfo.cache, therefore io.elementary.code.desktop comes before io.elementary.files.desktop.

Another elementary OS application that opens folders, Terminal, avoids a conflict by having a separate, hidden shortcut named open-pantheon-terminal-here.desktop which handles the inode/directory association. Accordingly, I have made one for code called open-pantheon-code-here.desktop.

@quequotion
Copy link
Author

quequotion commented Aug 9, 2020

I don't know what I'm doing with meson.

I think this should be an easy patch-in but I don't know what's triggering meson to attempt to overwrite the config target.

Help?

Edit: this got resolved, btw.

data/meson.build Outdated Show resolved Hide resolved
Use a separate .desktop to handle inode/directory for Code--the
same way Terminal does this. Other programs should not interfere
with Files' (or user's configured file browser) ownership of
inode/directory. This causes problems, like Plank's Trash Can
opening the trash directory in the wrong program.

When right clicking a folder in Files, the "Open in..." context
menu will direct users to Code.
@jeremypw
Copy link
Collaborator

I am not entirely sure this is the root cause of the original issue - it should be possible to have multiple applications able to accept the same mimetype (e.g. inode/directory) without them conflicting. You just have one set to the default for that mimetype. For example I have more than one filemanager installed but Files is the default and this opens unless I specifically use another one. I do not get the original problem with the the dock Trash can opening in Code anyway.
Info from mime-cache:

inode/directory=nautilus-folder-handler.desktop;nemo.desktop;io.elementary.code.desktop;io.elementary.files.desktop;open-pantheon-terminal-here.desktop;org.gnome.Nautilus.desktop;

@jeremypw
Copy link
Collaborator

jeremypw commented Aug 26, 2020

I cannot seem to trigger the dock Trash problem even if I edit my ./config/mimeapps.list to put Code first in the Default Applications section, log out and log in. Have you reproduced this issue?

@quequotion
Copy link
Author

quequotion commented Aug 28, 2020

The problem is not with mimeapps.list (which users and Files may contol), but /usr/share/applications/mimeinfo.cache (which is invisibly generated by update-desktop-database on install of an application).

Edit: In fact, the settings in mimeapps.list are ignored by Plank's trash can, which is why you were unable to force the issue by editing that file.

Edit again: I am not 100% sure of that. There are many other places overrides could be hiding; I am not familiar enough with plank to know if it has a preference.

Try this: delete or rename mimeapps.list; you will lose any mime handler settings you have chosen and revert to the generated settigs in mimeinfo.cache.

Edit: Unfortunately it may not be as simple as that, because there are many possible override files.

I have no setting for inode/directory in mimeapps.list.

This issue is 100% reproducible, but you have quite a few apps handling inode/directory. Among those that have the mime type specified in their vendor-supplied .desktop file, whichever comes first in alphanumerical order will be the one that takes priority in mimeinfo.cache (nonetheless, if your listing includes all of the available options, it looks like code will end up first).

Edit: It has been proven, conclusively, that the reason this issue does not occur in elementary OS is that the session-settings package provides an override. Anyone attempting to use Code in another distribution or desktop environment is likely to be affected.

begin rant:

In the bigger picture, the freedesktop mime handling model is an extremely fragile piece of poorly understood filigree. There are several different files serving the same purpose and overriding each other in scarcely documented ways, deprecated files (like defaults.list) are still supported and frequently used, etc. and this is just a subtopic of the larger mess that is the freedesktop shortcut & menu specification.

The most robust solution would be to deprecate everything other than /usr/share/applications/mimeinfo.cache (to be generated automatically when applications are installed) and ~/.local/share/applications/mimeapps.list (to be edited by users) and establish a precedent of prepending a priority number to .desktop filenames (ie, the way it is done with config files for udev, etc.: 00_file-manager.desktop, 20_folder-handling-app.desktop). Then of course write applications to honor settings from both.

:end rant

@quequotion
Copy link
Author

The freedesktop documentation states:

If a mime type is listed multiple times (either in the same file, or in another file further down the search path), the latter mention wins.

https://specifications.freedesktop.org/desktop-entry-spec/0.9.5/ar01s07.html

However, my findings are that it lists them in alphanumerical order, giving priority to the first in the list.

Neither behavior is conducive to a consistent workflow with multiple applications handling the same mime type.

@quequotion
Copy link
Author

quequotion commented Oct 3, 2020

@jeremypw
I went to look up who got this right with Terminal, and I found it was you!

What you did there was the right thing to do: separate folder handling into its own .desktop with a name that orders alphanumerically after Files.

You should really do the same with Code, trust me.

I can't be sure why you were unable to reproduce the issue on your system, but my guess is that you have defaults specified in multiple places, overriding the changes you made.

There are about a half dozen files in which these defaults could be specified, some shipped with elementary OS and others you may have (inadvertently) created.

@jeremypw
Copy link
Collaborator

jeremypw commented Oct 3, 2020

I think that the Terminal solution does not (now) suffer this problem is probably fortuitous - I think that at the time, the Terminal desktop file was named pantheon-terminal.desktop so the sort order was different.

@jeremypw
Copy link
Collaborator

jeremypw commented Oct 3, 2020

Have you checked what (if any) current legitimate use is made of the inode/directory association? Presumably it was put there for a reason? Need to deal with any regressions caused by removing it.

@jeremypw
Copy link
Collaborator

jeremypw commented Oct 3, 2020

If a mime type is listed multiple times (either in the same file, or in another file further down the search path), the latter mention wins.

Out of interest, what is your $XDG_DATA_DIRS ? Mine is `/usr/share/gnome:/usr/share/pantheon:/home/jeremy/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop

I still feel we are not dealing with the root cause here. Relying on the sort order of the names of desktop files feels at best a hack You may well be right that the mime-handling model is flawed but there is no evidence at present that the issue is widespread and not a quirk of your particular set up.
`

Copy link
Collaborator

@jeremypw jeremypw left a comment

Choose a reason for hiding this comment

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

This change interferes with the ability to launch Code with a directory as a parameter, which it opens as a project folder. This is because your new desktop file simply launches the same commandline as the original - but Code no longer is associated with inode/directory so the parameter is ignored.

The way Terminal does it is to have a commandline option to open a directory and this is used in the "open --- here" desktop file.

You could do the same with Code but as mentioned previously I am not convinced the issue is systemic.

@quequotion
Copy link
Author

quequotion commented Oct 4, 2020

This change interferes with the ability to launch Code with a directory as a parameter, which it opens as a project folder. This is because your new desktop file simply launches the same commandline as the original - but Code no longer is associated with inode/directory so the parameter is ignored.

That is not the case. Here's a video to prove that it is not the case.

Here's another video illustrating the initial problem.

I am certain the reason you have not yet reproduced this issue is that you have overrides somewhere other than /usr/share/applications/mimeinfo.cache (this could be considered the lowest level of the freedesktop mime association hierarchy). Such overrides would include any of the various possiblities in your home directory or system directories.

I note that session-settings now ships an overrides file (probably installed to /etc/xdg/pantheon-mimeapps.list), which sets inode/directory=io.elementary.files.desktop.

I do not have overrides for inode/directory in any of those files, in any of those locations.

The issue is systemic: Code's application .desktop holding the inode/directory association takes priority over Files' application .desktop, since it ends up alphanumerically ordered earlier in /usr/share/applications/mimeinfo.cache.

Whichever application is listed first on that line is what opens Plank's trash can, ergo the order of applications listed on each line of this file is meaningful: the first one is the system's default association (unless you have overrides somewhere).

The solution is to move the inode/directory association to an independent .desktop file (with NoDisplay=True to hide it from the application menu and a filename alphanumerically after Files' .desktop file to preserve order in mimeinfo.cache), which can then be accessed from Files' "Open in.." context menu (and not risk ownership conflicts or rely on overrides).

@jeremypw
Copy link
Collaborator

jeremypw commented Oct 4, 2020

My comments are based on running this PR on an up to date copy of Odin in a VM (Virtual Box) - I have not modified the original install.

@tintou What is your opinion?

@quequotion
Copy link
Author

My comments are based on running this PR on an up to date copy of Odin in a VM (Virtual Box) - I have not modified the original install.

I think this means elementary OS comes with overrides, at least pantheon-mimeapps.list. Does onboarding create or populate any of the user-directory files?

The 'quirk' of my setup, in this respect, is likely that it is exceedingly default.

@jeremypw
Copy link
Collaborator

@davidmhewitt I would value your opinion on this - is it a real issue and is this fix appropriate?

@jeremypw jeremypw marked this pull request as draft June 23, 2021 16:14
@quequotion quequotion marked this pull request as ready for review July 18, 2021 12:11
@jeremypw jeremypw marked this pull request as draft September 28, 2021 17:47
@jeremypw
Copy link
Collaborator

Converting to draft as it needs further work before reviewing. @quequotion If you are not still working on this maybe consider closing it?

@quequotion
Copy link
Author

quequotion commented Sep 28, 2021

Converting to draft as it needs further work before reviewing. @quequotion If you are not still working on this maybe consider closing it?

I am still very much advocating for this.

The only issue here is what we should name the separate, hidden shortcut that handles the inode/directory association.

I followed your example in Terminal, and named it open-pantheon-code-here.desktop.

As has been pointed out, the limitation of that is if someone is using a file manager with a shortcut name that would list alphanumerically after 'open'. This is a fundamental flaw in how everyone implements the freedesktop design: we ought to be prepending '.desktop' shortcut names with priority numbers, just like udev rules and other config files use.

Another way to handle this would be to prepend the hidden shortcut's name with a character that would ensure it lists alphanumerically last, but it's not pretty: zz-open-pantheon-code-here.desktop or !!-open-pantheon-code-here.desktop

Whichever solution you prefer, by the way, needs to be applied to Terminal's hidden shortcut as well.

In any case, as I said before, instead of closing this, append it to the Distro-agnostic Pantheon project.

This issue affects anyone who attempts to use Code without the session-settings package.

Edit: It's been a while since I read through the whole discussion. I had forgotten @davidmhewitt wanted a comment in the meson file explaining this; should be easy to add when I get a moment.

@jeremypw jeremypw added this to In progress in Distro-agnostic Pantheon via automation Sep 29, 2021
Fully explain the need to do this (the same thing that was done for Terminal). Since other distributions and desktop environments cannot be relied on to provide overrides that ensure a specific file manager gets priority for the inode/directory association, Code must attempt to avoid making itself the default handler.
@quequotion quequotion marked this pull request as ready for review September 29, 2021 08:30
@jeremypw
Copy link
Collaborator

As there does seem to be an official project to make pantheon apps distro-agnostic I am not averse to merging this although it is not required for ElementaryOS assuming no regressions/adverse side-effects in Elementary, subject to @davidmhewitt 's approval.

@davidmhewitt davidmhewitt moved this from In progress to Needs review in Distro-agnostic Pantheon Sep 29, 2021
Copy link
Member

@davidmhewitt davidmhewitt left a comment

Choose a reason for hiding this comment

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

This new file needs adding to po/extra/POTFILES https://github.com/elementary/code/blob/master/po/extra/POTFILES

@Marukesu
Copy link
Contributor

I followed your example in Terminal, and named it open-pantheon-code-here.desktop.

That isn't gonna work with flatpak, flatpak requires that exported .desktop files have the app-id as prefix, so it would need to be io.elementary.code.open-directory.desktop or something similar, that won't fix this.

the limitation of that is if someone is using a file manager with a shortcut name that would list alphanumerically after 'open'

Well, that already get any flatpak that starts with org., like org.gnome.Nautilus and org.kde.Dolphin, i believe they are also using the RDNN in the non-flatpak versions.

i believe this issue in GLib is what we want.

@jeremypw
Copy link
Collaborator

jeremypw commented Oct 1, 2021

Will the distro-agnostic project continue to support distros/users that do not use the flatpak'd version? Even so, failure to work under Flatpak is another reason not to merge this but wait for the upstream fix.

@quequotion
Copy link
Author

How is this being handled in Terminal, which is still using open-pantheon-terminal-here.desktop? Is Terminal available as a flatpak?

The report @Marukesu has linked is, like my ranting in this one, a proposal to change the standard by adding priority numbers to .desktop shortcuts (using a new field rather than alternative filenames).

I am all for that, but curious how long it could take. I've just left a comment there myself and I note the previous one was two years ago.

@jeremypw
Copy link
Collaborator

jeremypw commented Oct 6, 2021

There are no plans as far as I am aware to Flatpak Terminal (or Files). I don't think either would work properly in a sandbox.

@quequotion
Copy link
Author

quequotion commented Oct 6, 2021

I got in touch with @dfaure-kdab as suggested in the report linked by @Marukesu.

Unfortunately, extending the .desktop file standard with the InitialPreference key has already been rejected on the xdg mailing list.

I plan to look up that discussion and see if I can't revive it, but I am not going to hold my breath for this solution.

Edit: Found it. See "New MimeType fields in .desktop", and pour yourself a drink.

@jeremypw
Copy link
Collaborator

I think this can be closed now as there appears little prospect of progress without external changes.

@jeremypw jeremypw closed this Jul 27, 2022
Distro-agnostic Pantheon automation moved this from Needs review to Done Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Move inode/directory mimetype association to another .desktop file and context menu in Files
4 participants