New GFile API to wrap OS-specific objects
While porting GLib to UWP/WinRT, @seungha.yang and I were looking at how to add support for reading/writing files outside of the app's sandbox using gio/GFile. That way our existing giosrc/giosink gstreamer elements will work out of the box.
The workflow on UWP is very similar to file-pickers on iOS/Android or XDG Portal inside Flatpak. User says, hey, I want to open this file, then:
With GTK, an app would call gtk_file_chooser_get_file()
which would spawn a file chooser and do magic and finally return a GFile
.
On WinRT, the app does something equivalent which spawns a file chooser and gets back an IStorageFile
(or list of IStorageFile
). This is where GLib comes in. If we wrap each IStorageFile
inside a GFile
, everything that uses GLib continues to work as before.
An example of the workflow using IStorageFile
is available in this WIP GStreamer MR for a UWP file source.
We have two options here:
-
Have a winrt-specific prefix and have
g_winrt_file_new_for_handle()
. Other winrt-specific things could go in that same prefix. -
Add
g_file_new_for_handle()
and have platform-specific implementations inside it. Currently, this would only be useful for WinRT and maybe iOS. The Android file chooser API is only available through Kotlin or Java.
(1) and (2) are identical from the app's point of view. The prototype would look like: GFile* g_*file_new_for_handle (gpointer handle);
and handle
would be IInspectable
(which can be either IStorageFile
or IStorageFolder
) when running on WinRT/UWP.
Opinions? Based on that, Seungha will be opening a merge request in the near future