xdg-mime prefers .desktop entries over mimeapps.list
Using KDE Plasma on Arch Linux, which uses the latest commit in this repo.
% pacman -Q xdg-utils xdg-utils 1.1.3+18+g0547886-4
According to this page, ~/.config/mimeapps.list should be at the top of the hierarchy(ignoring $desktop-mimeapps.list which I don't have), so I add an entry there, but xdg-mime still returns a different application than what I defined.
Nautilus and other programs respect the setting, but Chromium, which uses xdg-open, does not.
% xdg-mime query default application/x-7z-compressed kindlecomicconverter.desktop % echo '[Added Associations]' > ~/.config/mimeapps.list % echo 'application/x-7z-compressed=org.gnome.FileRoller.desktop;' >> ~/.config/mimeapps.list % xdg-mime query default application/x-7z-compressed kindlecomicconverter.desktop
This seems to be caused because in most cases,
xdg-mime will only ever use .desktop entries instead of mimeapps.list.
% cat /usr/share/applications/kindlecomicconverter.desktop [Desktop Entry] Type=Application Version=1.0 Name=Kindle Comic Converter GenericName=Kindle Comic Converter Comment=Comic and Manga converter for e-book readers Icon=/usr/share/pixmaps/kcc.png Exec=/usr/bin/kcc %f Terminal=false Categories=Graphics; MimeType=application/zip;application/x-rar;application/x-7z-compressed;
The documentation makes it seem normal that mimeapps.list isn't even taken into consideration:
query default mimetype: Returns the default application that the desktop environment uses for opening files of type mimetype. The default application is identified by its *.desktop file.
But judging from the issue tracker and XDG spec, mimeapps.list should be on top of the food chain.
does ~/.config/mimeapps.list exist? (if so, that is prefered)
The issue and confusion seems to stem from these functions:
- defapp_fallback - returns the mimeapps.list entry
- defapp_kde - returns based on .desktop via ktrader - seems like ktrader is the culprit here, reported upstream
- defapp_generic - returns based on .desktop and
Default Applicationsin mimeapps.list. If it fails, it uses defapp_fallback.
This is an issue because
defapp_generic PREFERS the .desktop entries, and ignores
% XDG_CURRENT_DESKTOP="KDE" xdg-mime query default application/x-7z-compressed org.gnome.Nautilus.desktop % XDG_CURRENT_DESKTOP="" xdg-mime query default application/x-7z-compressed org.gnome.Nautilus.desktop % XDG_CURRENT_DESKTOP="nonexistent" xdg-mime query default application/x-7z-compressed org.gnome.FileRoller.desktop
And when I remove all .desktop entries:
% XDG_CURRENT_DESKTOP="KDE" xdg-mime query default application/x-7z-compressed % XDG_CURRENT_DESKTOP="" xdg-mime query default application/x-7z-compressed % XDG_CURRENT_DESKTOP="nonexistent" xdg-mime query default application/x-7z-compressed org.gnome.FileRoller.desktop
defapp_kde function, this seems to happen because when
XDG_CURRENT_DESKTOP is set to something unknown for
detectDE function will figure out it's KDE via fallbacks, but
ktraderclient5 will still use what is in
XDG_CURRENT_DESKTOP. And it seems to only show desktop entries if one passes
KDE to it.
 % XDG_CURRENT_DESKTOP="KDE" /usr/bin/ktraderclient5 --mimetype application/x-7z-compressed --servicetype Application mimetype is : application/x-7z-compressed servicetype is : Application got 0 offers.  % XDG_CURRENT_DESKTOP="nonexistent" /usr/bin/ktraderclient5 --mimetype application/x-7z-compressed --servicetype Application mimetype is : application/x-7z-compressed servicetype is : Application got 1 offers. ---- Offer 0 ---- Invalid property NotShowIn StartupNotify : 'TRUE' TryExec : 'file-roller' Invalid property X-GNOME-DocPath X-GNOME-UsesNotifications : 'TRUE' Type : 'Application' Name : 'Archive Manager' Comment : 'Create and modify an archive' Invalid property GenericName Icon : 'org.gnome.ArchiveManager' Exec : 'file-roller %U' Terminal : 'FALSE' Invalid property TerminalOptions Invalid property Path ServiceTypes : 'application/epub+zip - application/gzip - application/vnd.android.package-archive - application/vnd.ms-cab-compressed - application/vnd.debian.binary-package - application/x-7z-compressed - application/x-7z-compressed-tar - application/x-ace - application/x-alz - application/x-ar - application/x-archive - application/x-arj - application/x-brotli - application/x-bzip-brotli-tar - application/x-bzip - application/x-bzip-compressed-tar - application/x-bzip1 - application/x-bzip1-compressed-tar - application/x-cabinet - application/x-cd-image - application/x-compress - application/x-compressed-tar - application/x-cpio - application/x-chrome-extension - application/x-deb - application/x-ear - application/x-ms-dos-executable - application/x-gtar - application/x-gzip - application/x-gzpostscript - application/x-java-archive - application/x-lha - application/x-lhz - application/x-lrzip - application/x-lrzip-compressed-tar - application/x-lz4 - application/x-lzip - application/x-lzip-compressed-tar - application/x-lzma - application/x-lzma-compressed-tar - application/x-lzop - application/x-lz4-compressed-tar - application/x-lzop-compressed-tar - application/x-ms-wim - application/x-rar - application/x-rar-compressed - application/x-rpm - application/x-source-rpm - application/x-rzip - application/x-rzip-compressed-tar - application/x-tar - application/x-tarz - application/x-stuffit - application/x-war - application/x-xz - application/x-xz-compressed-tar - application/x-zip - application/x-zip-compressed - application/x-zoo - application/zip - Application' AllowAsDefault : 'TRUE' InitialPreference : '1' Invalid property Library DesktopEntryPath : '/usr/share/applications/org.gnome.FileRoller.desktop' DesktopEntryName : 'org.gnome.fileroller' Keywords : 'zip - tar - extract - unpack' FormFactors : '' Categories : 'GTK - GNOME - Utility - Archiving - Compression - X-GNOME-Utilities'
Workaround for KDE:
Make second line of /bin/xdg-open and /bin/xdg-mime