-
-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
If you open the "FileChooser" through the xdg-desktop-portal, that's gonna open a host (RISC-V) file picker. This will expose files outside the rootfs. Not only that, but when you choose a file it will return a host path to the application, which isn't going to work.
#include <gio/gio.h>
#include <stdlib.h>
#include <stdio.h>
int main() {
GDBusConnection *connection;
GError *error = NULL;
connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
if (!connection) {
g_printerr("Failed to connect to session bus: %s\n", error->message);
g_error_free(error);
return 1;
}
GVariantBuilder options_builder;
g_variant_builder_init(&options_builder, G_VARIANT_TYPE("a{sv}"));
// Add options if needed
g_variant_builder_add(&options_builder, "{sv}", "modal", g_variant_new_boolean(TRUE));
g_variant_builder_add(&options_builder, "{sv}", "multiple", g_variant_new_boolean(FALSE));
g_variant_builder_add(&options_builder, "{sv}", "title", g_variant_new_string("Select a file"));
GVariant *response = g_dbus_connection_call_sync(
connection,
"org.freedesktop.portal.Desktop", // destination
"/org/freedesktop/portal/desktop", // object path
"org.freedesktop.portal.FileChooser", // interface
"OpenFile", // method
g_variant_new("(ssa{sv})", // input signature
"", // parent_window (can be empty)
"file-open", // handle_token (arbitrary)
&options_builder), // options
NULL, // expected reply type
G_DBUS_CALL_FLAGS_NONE,
-1, // timeout (default)
NULL,
&error
);
if (!response) {
g_printerr("Call failed: %s\n", error->message);
g_error_free(error);
return 1;
}
g_print("File picker opened, waiting for user...\n");
g_variant_unref(response);
g_object_unref(connection);
return 0;
}
Compile as gcc file_picker.c
pkg-config --cflags --libs gio-2.0 -o file_picker
Metadata
Metadata
Assignees
Labels
No labels