How can an application open a file opened with it?

I apologise if this is not the correct forum for asking this question.
I am making a GTK4 application in Python which can open .odt files. If a .odt file is opened with the application in the file manager (i.e. the path to a document is passed to the application as an argument in the CLI), the Gio.Application emits the “open” signal. The function attached to this signal is then given an array of GFiles which have the path to those files. But, since the GFile has the actual file path associated with it (/home/user/…) instead of /run/user/100… which is the case with files opened manually using Gtk.FileDialog, the application is unable to read this file from within the sandbox. I have added --file-forwarding to the desktop file but it does not help.

How do I access the contents of these GFiles from within the sandbox?

If you want to use --file-forwarding, you need to enclose the paths inside a pair of @@. Flatpak will convert the host path to one valid in the sandbox then.

See also the description for the --file-forwarding argument in the man page for flatpak-run for reference.

If your app has an desktop file, Flatpak will do the necessary adaptations to it for you when it exports it, so you shouldn’t add --file-forwarding to your desktop file yourself. Just ensure the desktop file is correct and uses the same application id as your Flatpak, then Flatpak should take care of it.

Thank you, that solved my issue!

This topic was automatically closed after 32 hours. New replies are no longer allowed.