"gio open" opening file in a different program than "gio mime [mimetypehere]" suggests
x-scheme-handler/file=emacs.desktop overrode everything.
The problem
Dino, my chat program, opens .webm in Emacs instead of MPV.
The diagnostics
Per https://github.com/dino/dino/issues/916#issuecomment-1006535011 looks like Dino uses the https://valadoc.org/gio-2.0/GLib.AppInfo.launch_default_for_uri.html method.
I think this means that I need to use gio instead of xdg-open when diagnosing any issues like this.
Anyways, I downloaded a sample file (webm) and saved it as test.webm
file test.webm --mime returned video/webm; charset=binary
gio mime video/webm returned
rt@hp400 /home/rt $ gio mime video/webm
So if I run gio open test.webm, it should open in MPV right?
WRONG, it opens in Emacs and I can see the bytes.
The solution
In my ~/.config/mimeapps.list I had x-scheme-handler/file=emacs.desktop in the [Default Applications] section.
By having quick look at the source code, I suspect that gio could be turning e.g. gio open test.webm into gio open file:///home/rt/test.webm
That means it could be adding a file:// scheme, and the x-SCHEME-handler/FILE took precedence over anything else; because it saw the url scheme handler matches, used that and didn’t proceed to check the mime.
EDIT day later: it really is like that, see: https://gitlab.gnome.org/GNOME/glib/-/blob/6c930587ad76561274b067043038ebcb70bdfefa/gio/gdesktopappinfo.c#L4736
Some more tidbits
The gio code that tries to match a content-type (mime) is here: https://gitlab.gnome.org/GNOME/glib/-/blob/main/gio/gdesktopappinfo.c#L4673-4697
It checks:
$HOME/.config
/etc/xdg
$HOME/.local/share/applications
/usr/local/share/applications/usr/local/share/applications
for what it calls “tweaks”. I can only assume that it means “mimeapps.list that explicitly assign an app to a mime type”.
I can’t go any further because my gdb-fu is weak and I don’t know how to de-reference the =GHasTable=s that keep the more interesting values
Just look at me and laugh:
(gdb) p **((UnindexedMimeTweaks**)(*dir->mime_tweaks)->values)
$91 = {additions = 0x7fffec0075a0, removals = 0x0, defaults = 0x7fffec007b30}
(gdb) p ((UnindexedMimeTweaks)(*dir->mime_tweaks)->values)
$92 = {additions = 0x7fffec0076c0, removals = 0x7ffff7cdd030 <g_str_hash>,
defaults = 0x7ffff7cdd010 <g_str_equal>}
(gdb) p ((UnindexedMimeTweaks)(*dir->mime_tweaks)->values).additions
$93 = (gchar **) 0x7fffec0076c0
Why the need for explicit mimeapps.list?
I’m “disappointed” (hey, maybe it has to work that way?) that I need to explicitly provide a mimeapps.list with the mime<->app assignments.
My .desktop entry already has an e.g. MimeType=video/mp4 in /usr/share/applications/mpv.desktop. After I run sudo update-mime-database, I’ll have /usr/share/applications/mimeinfo.cache.
In mimeinfo.cache, I have the line video/quicktime=mpv.desktop;. It’s the only association for that mimetype in the whole file.
Why does gio insist that I provide an explicit app association in e.g. $HOME/.config/mimeapps.list, instead (in case it doesn’t find an association), just falling back to mimeinfo.cache?