这是indexloc提供的服务,不要输入任何密码
Skip to content

Think about the xdg-desktop-portal filepicker #257

@OFFTKP

Description

@OFFTKP

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions