~robertgzr/porta

ebbbccddce86ef60cb636c02e06b5f6b297a5d8f — Robert Günzler 8 months ago af194fb master
support access portal

Signed-off-by: Robert Günzler <r@gnzler.io>
2 files changed, 41 insertions(+), 0 deletions(-)

A src/access.rs
M src/main.rs
A src/access.rs => src/access.rs +39 -0
@@ 0,0 1,39 @@
use std::collections::HashMap;
use std::error::Error;

use zbus::{
    blocking::Connection,
    dbus_proxy,
    zvariant::{OwnedObjectPath, Value},
};

#[dbus_proxy(
    default_service = "org.freedesktop.portal.Desktop",
    default_path = "/org/freedesktop/portal/desktop",
    interface = "org.freedesktop.portal.Access"
)]
trait Access {
    fn access_dialog(
        &self,
        parent_window: &str,
        title: &str,
        subtitle: &str,
        body: &str,
        options: HashMap<&str, &Value<'_>>,
    ) -> zbus::Result<OwnedObjectPath>;
}

pub fn call(conn: &Connection, args: Vec<String>) -> zbus::Result<OwnedObjectPath> {
    AccessProxyBlocking::new(conn)?.access_dialog(
        "",
        args.get(0).unwrap_or(&"".to_owned()),
        args.get(1).unwrap_or(&"".to_owned()),
        args.get(2).unwrap_or(&"".to_owned()),
        HashMap::from([("modal", &Value::Bool(true))]),
    )
}

pub fn handle_reply(result: &HashMap<String, Value<'_>>) -> Result<(), Box<dyn Error>> {
    println!("{:?}", result);
    Ok(())
}

M src/main.rs => src/main.rs +2 -0
@@ 1,3 1,4 @@
mod access;
mod filechooser;
mod openuri;



@@ 67,6 68,7 @@ fn main() -> Result<(), Box<dyn Error>> {
    let args: Vec<String> = args[2..].into();

    match command {
        "access" => execute(&conn, args, access::call, access::handle_reply)?,
        "filechooser" => execute(&conn, args, filechooser::call, filechooser::handle_reply)?,
        "open-uri" => execute(&conn, args, openuri::call, openuri::handle_reply)?,
        _ => usage(),