Open a pdf file with the default pdf viewer from the installed snap failed

Hello,

My snap (Gnome-Referencer) runs in devmode. From this app, you can trigger to open a pdf document with the default pdf viewer. However, this functionality doesn’t works :
I got the following debug message : Exception: No application is registered as handling this file.
It seems that the program call the function Gio::AppInfo::launch_default_for_uri() to open this file (but I am not sure, I am not the author of this software nor familiar with the language used).

However, this functionality works well, if I build the software from its source. Thus it comes from my snap package. Moreover, this functionality is very important as this software is designed to manage a bibliography.

I was wondering if some plugs are missing in my yaml file… Have you any idea/suggestions ?

See the plugs I tried bellow

apps    
    plugs: 
        - x11
        - home
        - desktop
        - unity7
#        - network-control
#        - mount-observe
#        - gsettings
        - network
        - desktop-legacy
        - wayland
#        - classic-support

Also, I check logs with the snap-debug program and I got many massages like :

= AppArmor =
Time: Jul 22 00:21:21
Log: apparmor=“ALLOWED” operation=“dbus_method_call” bus=“session” path="/org/gnome/GConf/Client" interface=“org.gnome.GConf.Client” member=“Notify” name=":1.98" mask=“receive” pid=25901 label=“snap.referencer.referencer” peer_pid=15879 peer_label=“unconfined”
DBus access

= AppArmor =
Time: Jul 22 00:21:21
Log: apparmor=“ALLOWED” operation=“dbus_method_call” bus=“session” path="/org/gnome/GConf/Database/0" interface=“org.gnome.GConf.Database” member=“Set” mask=“send” name=“org.gnome.GConf” pid=25901 label=“snap.referencer.referencer” peer_pid=15879 peer_label=“unconfined”
DBus access

= AppArmor =
Time: Jul 22 00:01:55
Log: apparmor=“ALLOWED” operation=“open” profile=“snap.referencer.referencer” name="/snap/core/4917/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21" pid=25901 comm=“referencer” requested_mask=“r” denied_mask=“r” fsuid=1000 ouid=0
File: /snap/core/4917/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21 (read)
Suggestion:

  • adjust program to read necessary files from $SNAP, $SNAP_DATA, $SNAP_COMMON, $SNAP_USER_DATA or $SNAP_USER_COMMON

Thank you for your help.

Opening PDF files via the XDG mechanisms which GIO backs onto for this feature is currently not a whitelisted action. Snapd only permits limited xdc-open URLs such as http:// and https://, preventing file:/// from working. The work @jamesh is putting into portals might alleviate some of these problems, but it’s not ready yet.

The first thing I’d try is installing the xdg-desktop-portal package and try running your app with GTK_USE_PORTAL=1 set in the environment, and see if it works. That is the preferred system we want to use going forward.

We also did some work to allow the /usr/bin/xdg-open proxy to open local files (with an ownership check). It won’t be picked up by launch_default_for_uri() though, as there is no facility to set a catch all mime handler.

For Firefox, we used a mimeapps.list file to direct many common mime types to the helper:

We haven’t recommended other people do this because it won’t work for mime types not on the list, and interferes with portal support (glib will only use portals as a fallback when no other handler is found).

Thank you both for your answers.

Following advices on this forum, I developped this snap from ubuntu 16.04 and it seems that xdg-desktop-portal works only with newer version of snap and ubuntu.

However, I modified the software source code to call the C function system() + xdg-open instead of launch_default_for_uri() so that :
launch_default_for_uri(mypdf) becomes system(“xdg-open mypdf”).
It looks like it works ! when clicking on my pdf inside referencer, xdg-open prompt a window to ask permission to open the pdf, and then open it with the default pdf viewer.

However I need to check 1 things :

  • I upgraded to snap edge on my ubuntu 16.04 (so maybe it won’t work with stable…??)

The good news is that I tried to install and run the snap on ubuntu 18.04 and this functionnality works with xdg-open without any snap upgrade.

switching your snapd on 16.04 back from edge to stable is a matter of seconds:

sudo snap refresh core --stable

(and you can at any time switch to --edge again with the above command if you feel like)