| 1 |
use std::sync::Arc; |
| 2 |
|
| 3 |
use async_trait::async_trait; |
| 4 |
|
| 5 |
use crate::{ |
| 6 |
MaybeAppID, WindowIdentifierType, |
| 7 |
backend::{ |
| 8 |
Result, |
| 9 |
request::{Request, RequestImpl}, |
| 10 |
}, |
| 11 |
desktop::{ |
| 12 |
HandleToken, |
| 13 |
account::{UserInformation, UserInformationOptions}, |
| 14 |
request::Response, |
| 15 |
}, |
| 16 |
zvariant::{Optional, OwnedObjectPath}, |
| 17 |
}; |
| 18 |
|
| 19 |
#[async_trait] |
| 20 |
pub trait AccountImpl: RequestImpl { |
| 21 |
#[doc(alias = "GetUserInformation")] |
| 22 |
async fn get_user_information( |
| 23 |
&self, |
| 24 |
token: HandleToken, |
| 25 |
app_id: Option<MaybeAppID>, |
| 26 |
window_identifier: Option<WindowIdentifierType>, |
| 27 |
options: UserInformationOptions, |
| 28 |
) -> Result<UserInformation>; |
| 29 |
} |
| 30 |
|
| 31 |
pub(crate) struct AccountInterface { |
| 32 |
imp: Arc<dyn AccountImpl>, |
| 33 |
spawn: Arc<dyn futures_util::task::Spawn + Send + Sync>, |
| 34 |
cnx: zbus::Connection, |
| 35 |
} |
| 36 |
|
| 37 |
impl AccountInterface { |
| 38 |
pub fn new( |
| 39 |
imp: Arc<dyn AccountImpl>, |
| 40 |
cnx: zbus::Connection, |
| 41 |
spawn: Arc<dyn futures_util::task::Spawn + Send + Sync>, |
| 42 |
) -> Self { |
| 43 |
Self { imp, cnx, spawn } |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
#[zbus::interface(name = "org.freedesktop.impl.portal.Account")] |
| 48 |
impl AccountInterface { |
| 49 |
#[zbus(property(emits_changed_signal = "const"), name = "version")] |
| 50 |
fn version(&self) -> u32 { |
| 51 |
1 |
| 52 |
} |
| 53 |
|
| 54 |
#[zbus(name = "GetUserInformation")] |
| 55 |
#[zbus(out_args("response", "results"))] |
| 56 |
async fn get_user_information( |
| 57 |
&self, |
| 58 |
handle: OwnedObjectPath, |
| 59 |
app_id: Optional<MaybeAppID>, |
| 60 |
window_identifier: Optional<WindowIdentifierType>, |
| 61 |
options: UserInformationOptions, |
| 62 |
) -> Result<Response<UserInformation>> { |
| 63 |
let imp = Arc::clone(&self.imp); |
| 64 |
|
| 65 |
Request::spawn( |
| 66 |
"Account::GetUserInformation", |
| 67 |
&self.cnx, |
| 68 |
handle.clone(), |
| 69 |
Arc::clone(&self.imp), |
| 70 |
Arc::clone(&self.spawn), |
| 71 |
async move { |
| 72 |
imp.get_user_information( |
| 73 |
HandleToken::try_from(&handle).unwrap(), |
| 74 |
app_id.into(), |
| 75 |
window_identifier.into(), |
| 76 |
options, |
| 77 |
) |
| 78 |
.await |
| 79 |
}, |
| 80 |
) |
| 81 |
.await |
| 82 |
} |
| 83 |
} |