Debian Codegraph @

src/backend/email.rs

raw
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::{HandleToken, email::EmailOptions, request::Response},
12 zvariant::{Optional, OwnedObjectPath},
13 };
14
15 #[async_trait]
16 pub trait EmailImpl: RequestImpl {
17 #[doc(alias = "ComposeEmail")]
18 async fn compose(
19 &self,
20 token: HandleToken,
21 app_id: Option<MaybeAppID>,
22 window_identifier: Option<WindowIdentifierType>,
23 options: EmailOptions,
24 ) -> Result<()>;
25 }
26
27 pub(crate) struct EmailInterface {
28 imp: Arc<dyn EmailImpl>,
29 spawn: Arc<dyn futures_util::task::Spawn + Send + Sync>,
30 cnx: zbus::Connection,
31 }
32
33 impl EmailInterface {
34 pub fn new(
35 imp: Arc<dyn EmailImpl>,
36 cnx: zbus::Connection,
37 spawn: Arc<dyn futures_util::task::Spawn + Send + Sync>,
38 ) -> Self {
39 Self { imp, cnx, spawn }
40 }
41 }
42
43 #[zbus::interface(name = "org.freedesktop.impl.portal.Email")]
44 impl EmailInterface {
45 #[zbus(property(emits_changed_signal = "const"), name = "version")]
46 fn version(&self) -> u32 {
47 4
48 }
49
50 #[zbus(out_args("response", "results"))]
51 async fn compose_email(
52 &self,
53 handle: OwnedObjectPath,
54 app_id: Optional<MaybeAppID>,
55 window_identifier: Optional<WindowIdentifierType>,
56 options: EmailOptions,
57 ) -> Result<Response<()>> {
58 let imp = Arc::clone(&self.imp);
59
60 Request::spawn(
61 "Email::ComposeEmail",
62 &self.cnx,
63 handle.clone(),
64 Arc::clone(&self.imp),
65 Arc::clone(&self.spawn),
66 async move {
67 imp.compose(
68 HandleToken::try_from(&handle).unwrap(),
69 app_id.into(),
70 window_identifier.into(),
71 options,
72 )
73 .await
74 },
75 )
76 .await
77 }
78 }