diff --git a/src/desktop_entry.rs b/src/desktop_entry.rs index c21e0fc..8ef26fb 100644 --- a/src/desktop_entry.rs +++ b/src/desktop_entry.rs @@ -1,7 +1,7 @@ //! # D-Bus interface proxy for: `org.desktopintegration.DesktopEntry` //! //! This code was generated by `zbus-xmlgen` `4.1.0` from D-Bus introspection data. -//! Source: `org.desktopintegration.DesktopEntry.xml`. +//! Source: `Interface '/org/desktopintegration/DesktopEntry' from service 'org.desktopintegration.DesktopEntry' on system bus`. //! //! You may prefer to adapt it, instead of using it verbatim. //! @@ -11,8 +11,8 @@ //! This type implements the [D-Bus standard interfaces], (`org.freedesktop.DBus.*`) for which the //! following zbus API can be used: //! -//! * [`zbus::fdo::PeerProxy`] //! * [`zbus::fdo::PropertiesProxy`] +//! * [`zbus::fdo::PeerProxy`] //! * [`zbus::fdo::IntrospectableProxy`] //! //! Consequently `zbus-xmlgen` did not generate code for the above interfaces. @@ -22,15 +22,15 @@ use zbus::proxy; #[proxy( interface = "org.desktopintegration.DesktopEntry", - default_path = "/org/desktopintegration/DesktopEntry", - assume_defaults = true + default_service = "org.desktopintegration.DesktopEntry", + default_path = "/org/desktopintegration/DesktopEntry" )] trait DesktopEntry { /// NewPersistentEntry method - fn new_persistent_entry(&self, appid: &str, entry: &str) -> zbus::Result<()>; + fn new_persistent_entry(&self, appid: &str, entry: &str, owner: &str) -> zbus::Result<()>; /// NewPersistentIcon method - fn new_persistent_icon(&self, name: &str, data: &[u8]) -> zbus::Result<()>; + fn new_persistent_icon(&self, name: &str, data: &[u8], owner: &str) -> zbus::Result<()>; /// NewProcessEntry method fn new_process_entry(&self, appid: &str, entry: &str) -> zbus::Result<()>; @@ -39,8 +39,14 @@ trait DesktopEntry { fn new_process_icon(&self, name: &str, data: &[u8]) -> zbus::Result<()>; /// NewSessionEntry method - fn new_session_entry(&self, appid: &str, entry: &str) -> zbus::Result<()>; + fn new_session_entry(&self, appid: &str, entry: &str, owner: &str) -> zbus::Result<()>; /// NewSessionIcon method - fn new_session_icon(&self, name: &str, data: &[u8]) -> zbus::Result<()>; + fn new_session_icon(&self, name: &str, data: &[u8], owner: &str) -> zbus::Result<()>; + + /// RemovePersistentOwner method + fn remove_persistent_owner(&self, owner: &str) -> zbus::Result<()>; + + /// RemoveSessionOwner method + fn remove_session_owner(&self, owner: &str) -> zbus::Result<()>; } diff --git a/src/main.rs b/src/main.rs index 80e8b56..15443c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use clap::Parser; use container_type::ContainerType; use ron::de::SpannedError; use serde::{Deserialize, Serialize}; +use server::ClientSetupError; use std::error::Error; use std::fmt::Display; use std::{env, fs, io}; @@ -32,6 +33,7 @@ enum CDEError { IO(io::Error), NoEnv(std::env::VarError), Ron(SpannedError), + ClientSetup(ClientSetupError), } impl Error for CDEError { @@ -54,6 +56,7 @@ impl Display for CDEError { Self::IO(e) => e.fmt(f), Self::NoEnv(e) => e.fmt(f), Self::Ron(e) => e.fmt(f), + Self::ClientSetup(e) => e.fmt(f), } } } @@ -76,6 +79,12 @@ impl From for CDEError { } } +impl From for CDEError { + fn from(value: ClientSetupError) -> Self { + Self::ClientSetup(value) + } +} + #[async_std::main] async fn main() -> Result<(), CDEError> { env_logger::init(); @@ -104,7 +113,7 @@ async fn main() -> Result<(), CDEError> { } let config_data: ContainerList = ron::from_str(&read_to_string(conf_path)?)?; - server::server(config_data).await; + server::server(config_data, "container-desktop-entries").await?; Ok(()) } diff --git a/src/server.rs b/src/server.rs index f9601a8..52f4e52 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,5 +1,6 @@ use std::{ env, + fmt::Display, fs::{self, create_dir, read, read_to_string}, io, path::{Path, PathBuf}, @@ -31,7 +32,16 @@ impl From for ClientSetupError { } } -pub async fn server(containers: ContainerList) { +impl Display for ClientSetupError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::IO(e) => e.fmt(f), + Self::Zbus(e) => e.fmt(f), + } + } +} + +pub async fn server(containers: ContainerList, owner: &str) -> Result<(), ClientSetupError> { let home = match env::var("RUNTIME_DIRECTORY") { Ok(h) => h, Err(_) => { @@ -39,6 +49,11 @@ pub async fn server(containers: ContainerList) { panic!() } }; + let connection = Connection::session().await?; + let proxy = DesktopEntryProxy::new(&connection).await?; + if let Err(e) = proxy.remove_session_owner(&owner).await { + log::error!("could not remove owner container-desktop-entries: {:?}", e); + } let to_path = Path::new(&home).join(Path::new(".cache/container-desktop-entries/")); for (container_name, container_type) in containers.containers { if container_type.not_supported() { @@ -48,16 +63,18 @@ pub async fn server(containers: ContainerList) { ); continue; } - if let Err(kind) = set_up_client(&container_name, container_type, &to_path).await { + if let Err(kind) = set_up_client(&container_name, container_type, &to_path, owner).await { log::error!("Error setting up client {}: {:?}", container_name, kind); } } + Ok(()) } async fn set_up_client( container_name: &str, container_type: ContainerType, to_path: &Path, + owner: &str, ) -> Result<(), ClientSetupError> { // Start client if client is not running start_client(container_name, container_type)?; @@ -148,7 +165,10 @@ async fn set_up_client( continue; // We don't want to push NoDisplay entries into our host } - match proxy.new_session_entry(&entry.appid, &file_text).await { + match proxy + .new_session_entry(&entry.appid, &file_text, owner) + .await + { Ok(_) => { log::info!("Daemon registered entry: {}", entry.appid); if let Some(icon_name) = entry.icon() { @@ -168,6 +188,7 @@ async fn set_up_client( .new_session_icon( icon_name, file_bytes.as_slice(), + owner, ) .await {