|
| 1 | +use crate::{PortalResponse, Session}; |
| 2 | +use std::{ |
| 3 | + collections::HashMap, |
| 4 | + env, |
| 5 | + os::{fd::OwnedFd, unix::net::UnixStream}, |
| 6 | +}; |
| 7 | +use zbus::zvariant; |
| 8 | + |
| 9 | +#[derive(zvariant::SerializeDict, zvariant::Type)] |
| 10 | +#[zvariant(signature = "a{sv}")] |
| 11 | +struct CreateSessionResult { |
| 12 | + session_id: String, |
| 13 | +} |
| 14 | + |
| 15 | +#[derive(zvariant::DeserializeDict, zvariant::Type)] |
| 16 | +#[zvariant(signature = "a{sv}")] |
| 17 | +struct SelectDevicesOptions { |
| 18 | + // Default: all |
| 19 | + types: Option<u32>, |
| 20 | + restore_data: Option<(String, u32, zvariant::OwnedValue)>, |
| 21 | + // Default: 0 |
| 22 | + persist_mode: Option<u32>, |
| 23 | +} |
| 24 | + |
| 25 | +#[derive(zvariant::SerializeDict, zvariant::Type)] |
| 26 | +#[zvariant(signature = "a{sv}")] |
| 27 | +struct StartResult { |
| 28 | + devices: u32, |
| 29 | + clipboard_enabled: bool, |
| 30 | + streams: Vec<(u32, HashMap<String, zvariant::OwnedValue>)>, |
| 31 | +} |
| 32 | + |
| 33 | +struct SessionData {} |
| 34 | + |
| 35 | +pub struct RemoteDesktop; |
| 36 | + |
| 37 | +#[zbus::interface(name = "org.freedesktop.impl.portal.RemoteDesktop")] |
| 38 | +impl RemoteDesktop { |
| 39 | + async fn create_session( |
| 40 | + &self, |
| 41 | + #[zbus(connection)] connection: &zbus::Connection, |
| 42 | + handle: zvariant::ObjectPath<'_>, |
| 43 | + session_handle: zvariant::ObjectPath<'_>, |
| 44 | + app_id: String, |
| 45 | + options: HashMap<String, zvariant::OwnedValue>, |
| 46 | + ) -> PortalResponse<CreateSessionResult> { |
| 47 | + connection |
| 48 | + .object_server() |
| 49 | + .at(&session_handle, Session::new(SessionData {}, |_| {})) |
| 50 | + .await |
| 51 | + .unwrap(); // XXX unwrap |
| 52 | + PortalResponse::Success(CreateSessionResult { |
| 53 | + session_id: "foo".to_string(), // XXX |
| 54 | + }) |
| 55 | + } |
| 56 | + |
| 57 | + // CreateSession |
| 58 | + async fn select_devices( |
| 59 | + &self, |
| 60 | + #[zbus(connection)] connection: &zbus::Connection, |
| 61 | + handle: zvariant::ObjectPath<'_>, |
| 62 | + session_handle: zvariant::ObjectPath<'_>, |
| 63 | + app_id: String, |
| 64 | + options: SelectDevicesOptions, // XXX |
| 65 | + ) -> PortalResponse<HashMap<String, zvariant::OwnedValue>> { |
| 66 | + PortalResponse::Success(HashMap::new()) |
| 67 | + } |
| 68 | + |
| 69 | + async fn start( |
| 70 | + &self, |
| 71 | + #[zbus(connection)] connection: &zbus::Connection, |
| 72 | + handle: zvariant::ObjectPath<'_>, |
| 73 | + session_handle: zvariant::ObjectPath<'_>, |
| 74 | + app_id: String, |
| 75 | + parent_window: String, |
| 76 | + options: HashMap<String, zvariant::OwnedValue>, |
| 77 | + ) -> PortalResponse<StartResult> { |
| 78 | + PortalResponse::Success(StartResult { |
| 79 | + devices: 7, |
| 80 | + clipboard_enabled: false, |
| 81 | + streams: Vec::new(), |
| 82 | + }) |
| 83 | + } |
| 84 | + |
| 85 | + async fn connect_to_EIS( |
| 86 | + &self, |
| 87 | + #[zbus(connection)] connection: &zbus::Connection, |
| 88 | + session_handle: zvariant::ObjectPath<'_>, |
| 89 | + app_id: String, |
| 90 | + options: HashMap<String, zvariant::OwnedValue>, |
| 91 | + ) -> zvariant::Fd { |
| 92 | + println!("Connect"); |
| 93 | + // TODO Dedicated mechanism to get fd, for specific "devices" |
| 94 | + if let Ok(path) = env::var("LIBEI_SOCKET") { |
| 95 | + if let Ok(socket) = UnixStream::connect(path) { |
| 96 | + return OwnedFd::from(socket).into(); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + todo!() |
| 101 | + //PortalResponse::Other |
| 102 | + } |
| 103 | + |
| 104 | + // TODO: Notify* |
| 105 | + |
| 106 | + #[zbus(property)] |
| 107 | + async fn available_device_types(&self) -> u32 { |
| 108 | + 7 // XXX |
| 109 | + } |
| 110 | + |
| 111 | + #[zbus(property, name = "version")] |
| 112 | + async fn version(&self) -> u32 { |
| 113 | + 2 |
| 114 | + } |
| 115 | +} |
0 commit comments