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

Flatpak/Snap apps open vscode instead of the file manager #842

Closed
nu111 opened this issue Jul 26, 2022 · 9 comments
Closed

Flatpak/Snap apps open vscode instead of the file manager #842

nu111 opened this issue Jul 26, 2022 · 9 comments

Comments

@nu111
Copy link

nu111 commented Jul 26, 2022

Hi,

when I open a directory from a Flatpak app such as DropBox or Cryptomator, or from a snap app like Chromium it opens it in Visual Studio Code instead of Dolphin. This doesn't happen if I open a directory from a non Flatpak/Snap app. Also xdg-open ~ as expected opens Dolphin.

Visual Studio Code is installed with apt, the official way to install it.

OS: Kubuntu 20.04.4
Flatpak: 1.6.5
Snap: 2.56.2

I have been directed here by this comment: flatpak/flatpak#4819 (comment)

@TDuffinNTU
Copy link

Easiest workaround for flatpak version of vscode is to run xdg-mime default org.kde.dolphin.desktop inode/desktop in a terminal. No idea why mimeinfo.cache doesn't pick it up properly but 🤷

@hfiguiere
Copy link
Collaborator

that's because VSCode seems to want to be the one opening them. I have a similar issue with RawTherapee (a digital camera raw processor) that steal it too.

Also I think the proper MIME type is inode/diretory.

@eingorz
Copy link

eingorz commented Nov 27, 2023

I have this issue, neither of the commands above fixed it

@RokeJulianLockhart
Copy link

microsoft/vscode#114425 (comment)

@killjoy1221
Copy link

I'm thinking something somewhere is incorrectly implemented. For me, xdg-open outside Flatpak opens Dolphin. But inside Flatpak, it opens vscode.

Using microsoft/vscode#114425 (comment), I can identify the issue by editing a file on the host system.

All the current system mime associations are located in /usr/share/applications/mimeinfo.cache. Mine has this association for inode/directory:

inode/directory=code.desktop;org.kde.dolphin.desktop;org.kde.gwenview.desktop;org.kde.kate.desktop;

Notice that code.desktop is first, probably because alphabetical order. As it works on the host system, I'll assume there's nothing wrong with the file. However, editing this file so org.kde.dolphin.desktop is first resolves the issue inside Flatpak.

Unfortunately, this file is automatically generated by update-desktop-database, so it isn't usable as a permanent workaround. Although, if you're willing to break any package updates, you could rename the the desktop file to something like vscode.desktop, though I don't know what other side-effects that may have

@smcv
Copy link
Collaborator

smcv commented Dec 8, 2023

The MIME type associations in mimeinfo.cache are in an undefined and unspecified order: it is a cache of every application that says it can open inode/directory, with no preference order implied. It is entirely likely that the GIO library used by xdg-desktop-portal, whatever is the equivalent code in the KDE ecosystem, and whatever xdg-open is using (if different) will choose a different arbitrary one from among the apps that claim to be able to open directories.

The solution to that is to use the mimeapps.list mechanisms defined by https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html to set a preferred/default handler for inode/directory from among the ones listed in mimeapps.cache. In practice, nearly everyone will want the preferred handler for inode/directory to be a file manager, but the system has no way to know that Dolphin is a file manager and VSCode isn't. mime-apps-spec is a higher layer than mimeinfo.cache: mimeinfo.cache is mechanism, and mimeapps.list is policy.

Two things are necessary for this to work as intended:

  1. If you are using a complete desktop environment like KDE or GNOME, it should be setting XDG_CURRENT_DESKTOP to a suitable value in the "activation environment" that xdg-desktop-portal will inherit from systemd --user or dbus-daemon, for example XDG_CURRENT_DESKTOP=KDE for KDE Plasma, or XDG_CURRENT_DESKTOP=Ubuntu:GNOME for Ubuntu's variant of GNOME. If you are using a desktop environment that you have assembled yourself from individual components, then you might need to do that piece of system-integration work yourself.

  2. If you are using a complete desktop environment like KDE or GNOME, then it should also be installing /usr/share/applications/${desktop}-mimeapps.list, where ${desktop} is one of the names in XDG_CURRENT_DESKTOP folded to lower-case: for example /usr/share/applications/kde-mimeapps.list would select KDE's Dolphin as preferred, or /usr/share/applications/gnome-mimeapps.list would select GNOME's Nautilus. Again, if you are using a desktop environment that you have assembled yourself from individual components, then you might need to do that piece of system-integration work yourself, either in a package, or in /etc/xdg/${desktop}-mimeapps.list, or per-user in ~/.config/mimeapps.list.

If you are using a complete desktop environment but it is not properly integrated in your distribution, so that one of the integration points I've described is missing, then please report that to your Linux distribution's bug reporting channels.

@TingPing
Copy link
Member

I'll close this as nothing is actionable. The comments above discuss how to configure the system.

@nu111
Copy link
Author

nu111 commented Dec 11, 2023

BTW I still don't understand what causes the misconfiguration and why it seems related to vscode.

@killjoy1221
Copy link

It's not specifically something that vscode does, but the name of the .desktop file (not a vscode bug). If you created an app named a.desktop and configured it to open directories, I bet it would use that instead of your default file manager as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triaged
Development

No branches or pull requests

8 participants