use std::{collections::HashMap, sync::Arc}; use async_trait::async_trait; use zbus::zvariant::{self, OwnedValue}; use crate::{ MaybeAppID, backend::{ Result, request::{Request, RequestImpl}, }, desktop::{HandleToken, Response}, }; #[async_trait] pub trait SecretImpl: RequestImpl { #[doc(alias = "RetrieveSecret")] async fn retrieve( &self, token: HandleToken, app_id: MaybeAppID, fd: std::os::fd::OwnedFd, ) -> Result>; } pub(crate) struct SecretInterface { imp: Arc, spawn: Arc, cnx: zbus::Connection, } impl SecretInterface { pub fn new( imp: Arc, cnx: zbus::Connection, spawn: Arc, ) -> Self { Self { imp, cnx, spawn } } } #[zbus::interface(name = "org.freedesktop.impl.portal.Secret")] impl SecretInterface { #[zbus(property(emits_changed_signal = "const"), name = "version")] fn version(&self) -> u32 { 1 } #[zbus(out_args("response", "results"))] async fn retrieve_secret( &self, handle: zvariant::OwnedObjectPath, app_id: MaybeAppID, fd: zvariant::OwnedFd, _options: HashMap, ) -> Result>> { let imp = Arc::clone(&self.imp); Request::spawn( "Secret::RetrieveSecret", &self.cnx, handle.clone(), Arc::clone(&self.imp), Arc::clone(&self.spawn), async move { imp.retrieve( HandleToken::try_from(&handle).unwrap(), app_id, std::os::fd::OwnedFd::from(fd), ) .await }, ) .await } }