Skip to content

Commit

Permalink
fix: use updated desktop entry interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanabx committed Apr 27, 2024
1 parent aa86a34 commit c749229
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
22 changes: 14 additions & 8 deletions src/desktop_entry.rs
Original file line number Diff line number Diff line change
@@ -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.
//!
Expand All @@ -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.
Expand All @@ -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<()>;
Expand All @@ -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<()>;
}
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -32,6 +33,7 @@ enum CDEError {
IO(io::Error),
NoEnv(std::env::VarError),
Ron(SpannedError),
ClientSetup(ClientSetupError),
}

impl Error for CDEError {
Expand All @@ -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),
}
}
}
Expand All @@ -76,6 +79,12 @@ impl From<SpannedError> for CDEError {
}
}

impl From<ClientSetupError> for CDEError {
fn from(value: ClientSetupError) -> Self {
Self::ClientSetup(value)
}
}

#[async_std::main]
async fn main() -> Result<(), CDEError> {
env_logger::init();
Expand Down Expand Up @@ -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(())
}
27 changes: 24 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
env,
fmt::Display,
fs::{self, create_dir, read, read_to_string},
io,
path::{Path, PathBuf},
Expand Down Expand Up @@ -31,14 +32,28 @@ impl From<zbus::Error> 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(_) => {
log::error!("RUNTIME_DIRECTORY NOT FOUND. Make sure you're using the service!");
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() {
Expand All @@ -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)?;
Expand Down Expand Up @@ -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() {
Expand All @@ -168,6 +188,7 @@ async fn set_up_client(
.new_session_icon(
icon_name,
file_bytes.as_slice(),
owner,
)
.await
{
Expand Down

0 comments on commit c749229

Please sign in to comment.