gtkzenityflatpak

Package an application using Flatpak that uses `zenity --file-selection` (or the GTK file selection dialog)


I have an application that uses zenity --file-selection to allow the user to select a file using a GUI.

This works very nicely until I package my application using Flatpak, as unfortunatly the sandboxing permissions cause zenity to hang (but only when the --file-selection option is used).

I wouldn't mind if it returned an error, or a blank a file name, as I could just ignore it and fail silently (which is what I do when the application attempts to launch zenity on systems that doesn't have it installed).

Unfortunately it hangs which in turn causes my application to hang which is not good...

The question is how do I modify the package manifest to allow the application to use zenity --file-selection ?

I have considered rewriting the application to use GTK but I don't think that using gtk_file_chooser_dialog and gtk_file_chooser_dialog_new is going to work either.

I'd also rather not to have to work out how deal with multiple versions of GTK on different platforms and maintaining a separate code base for just for Flathub is not something I want to do either.

Is there a magic sauce ?


Solution

  • Your manifest is correct. I don't know how zenity --file-selection works, but using the GTK native component, Gtk.FileDialog in the case of GTK4, it automatically interacts with the Portal needed to access files outside the sandbox.

    I'm not sure about the standard GTK3 components for this function but I believe they also automatically interact with the necessary Portal.