Skip to content
This repository was archived by the owner on Feb 16, 2025. It is now read-only.

Commit c749229

Browse files
committed
fix: use updated desktop entry interface
1 parent aa86a34 commit c749229

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

Diff for: src/desktop_entry.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! # D-Bus interface proxy for: `org.desktopintegration.DesktopEntry`
22
//!
33
//! This code was generated by `zbus-xmlgen` `4.1.0` from D-Bus introspection data.
4-
//! Source: `org.desktopintegration.DesktopEntry.xml`.
4+
//! Source: `Interface '/org/desktopintegration/DesktopEntry' from service 'org.desktopintegration.DesktopEntry' on system bus`.
55
//!
66
//! You may prefer to adapt it, instead of using it verbatim.
77
//!
@@ -11,8 +11,8 @@
1111
//! This type implements the [D-Bus standard interfaces], (`org.freedesktop.DBus.*`) for which the
1212
//! following zbus API can be used:
1313
//!
14-
//! * [`zbus::fdo::PeerProxy`]
1514
//! * [`zbus::fdo::PropertiesProxy`]
15+
//! * [`zbus::fdo::PeerProxy`]
1616
//! * [`zbus::fdo::IntrospectableProxy`]
1717
//!
1818
//! Consequently `zbus-xmlgen` did not generate code for the above interfaces.
@@ -22,15 +22,15 @@
2222
use zbus::proxy;
2323
#[proxy(
2424
interface = "org.desktopintegration.DesktopEntry",
25-
default_path = "/org/desktopintegration/DesktopEntry",
26-
assume_defaults = true
25+
default_service = "org.desktopintegration.DesktopEntry",
26+
default_path = "/org/desktopintegration/DesktopEntry"
2727
)]
2828
trait DesktopEntry {
2929
/// NewPersistentEntry method
30-
fn new_persistent_entry(&self, appid: &str, entry: &str) -> zbus::Result<()>;
30+
fn new_persistent_entry(&self, appid: &str, entry: &str, owner: &str) -> zbus::Result<()>;
3131

3232
/// NewPersistentIcon method
33-
fn new_persistent_icon(&self, name: &str, data: &[u8]) -> zbus::Result<()>;
33+
fn new_persistent_icon(&self, name: &str, data: &[u8], owner: &str) -> zbus::Result<()>;
3434

3535
/// NewProcessEntry method
3636
fn new_process_entry(&self, appid: &str, entry: &str) -> zbus::Result<()>;
@@ -39,8 +39,14 @@ trait DesktopEntry {
3939
fn new_process_icon(&self, name: &str, data: &[u8]) -> zbus::Result<()>;
4040

4141
/// NewSessionEntry method
42-
fn new_session_entry(&self, appid: &str, entry: &str) -> zbus::Result<()>;
42+
fn new_session_entry(&self, appid: &str, entry: &str, owner: &str) -> zbus::Result<()>;
4343

4444
/// NewSessionIcon method
45-
fn new_session_icon(&self, name: &str, data: &[u8]) -> zbus::Result<()>;
45+
fn new_session_icon(&self, name: &str, data: &[u8], owner: &str) -> zbus::Result<()>;
46+
47+
/// RemovePersistentOwner method
48+
fn remove_persistent_owner(&self, owner: &str) -> zbus::Result<()>;
49+
50+
/// RemoveSessionOwner method
51+
fn remove_session_owner(&self, owner: &str) -> zbus::Result<()>;
4652
}

Diff for: src/main.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use clap::Parser;
22
use container_type::ContainerType;
33
use ron::de::SpannedError;
44
use serde::{Deserialize, Serialize};
5+
use server::ClientSetupError;
56
use std::error::Error;
67
use std::fmt::Display;
78
use std::{env, fs, io};
@@ -32,6 +33,7 @@ enum CDEError {
3233
IO(io::Error),
3334
NoEnv(std::env::VarError),
3435
Ron(SpannedError),
36+
ClientSetup(ClientSetupError),
3537
}
3638

3739
impl Error for CDEError {
@@ -54,6 +56,7 @@ impl Display for CDEError {
5456
Self::IO(e) => e.fmt(f),
5557
Self::NoEnv(e) => e.fmt(f),
5658
Self::Ron(e) => e.fmt(f),
59+
Self::ClientSetup(e) => e.fmt(f),
5760
}
5861
}
5962
}
@@ -76,6 +79,12 @@ impl From<SpannedError> for CDEError {
7679
}
7780
}
7881

82+
impl From<ClientSetupError> for CDEError {
83+
fn from(value: ClientSetupError) -> Self {
84+
Self::ClientSetup(value)
85+
}
86+
}
87+
7988
#[async_std::main]
8089
async fn main() -> Result<(), CDEError> {
8190
env_logger::init();
@@ -104,7 +113,7 @@ async fn main() -> Result<(), CDEError> {
104113
}
105114
let config_data: ContainerList = ron::from_str(&read_to_string(conf_path)?)?;
106115

107-
server::server(config_data).await;
116+
server::server(config_data, "container-desktop-entries").await?;
108117

109118
Ok(())
110119
}

Diff for: src/server.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{
22
env,
3+
fmt::Display,
34
fs::{self, create_dir, read, read_to_string},
45
io,
56
path::{Path, PathBuf},
@@ -31,14 +32,28 @@ impl From<zbus::Error> for ClientSetupError {
3132
}
3233
}
3334

34-
pub async fn server(containers: ContainerList) {
35+
impl Display for ClientSetupError {
36+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37+
match self {
38+
Self::IO(e) => e.fmt(f),
39+
Self::Zbus(e) => e.fmt(f),
40+
}
41+
}
42+
}
43+
44+
pub async fn server(containers: ContainerList, owner: &str) -> Result<(), ClientSetupError> {
3545
let home = match env::var("RUNTIME_DIRECTORY") {
3646
Ok(h) => h,
3747
Err(_) => {
3848
log::error!("RUNTIME_DIRECTORY NOT FOUND. Make sure you're using the service!");
3949
panic!()
4050
}
4151
};
52+
let connection = Connection::session().await?;
53+
let proxy = DesktopEntryProxy::new(&connection).await?;
54+
if let Err(e) = proxy.remove_session_owner(&owner).await {
55+
log::error!("could not remove owner container-desktop-entries: {:?}", e);
56+
}
4257
let to_path = Path::new(&home).join(Path::new(".cache/container-desktop-entries/"));
4358
for (container_name, container_type) in containers.containers {
4459
if container_type.not_supported() {
@@ -48,16 +63,18 @@ pub async fn server(containers: ContainerList) {
4863
);
4964
continue;
5065
}
51-
if let Err(kind) = set_up_client(&container_name, container_type, &to_path).await {
66+
if let Err(kind) = set_up_client(&container_name, container_type, &to_path, owner).await {
5267
log::error!("Error setting up client {}: {:?}", container_name, kind);
5368
}
5469
}
70+
Ok(())
5571
}
5672

5773
async fn set_up_client(
5874
container_name: &str,
5975
container_type: ContainerType,
6076
to_path: &Path,
77+
owner: &str,
6178
) -> Result<(), ClientSetupError> {
6279
// Start client if client is not running
6380
start_client(container_name, container_type)?;
@@ -148,7 +165,10 @@ async fn set_up_client(
148165
continue; // We don't want to push NoDisplay entries into our host
149166
}
150167

151-
match proxy.new_session_entry(&entry.appid, &file_text).await {
168+
match proxy
169+
.new_session_entry(&entry.appid, &file_text, owner)
170+
.await
171+
{
152172
Ok(_) => {
153173
log::info!("Daemon registered entry: {}", entry.appid);
154174
if let Some(icon_name) = entry.icon() {
@@ -168,6 +188,7 @@ async fn set_up_client(
168188
.new_session_icon(
169189
icon_name,
170190
file_bytes.as_slice(),
191+
owner,
171192
)
172193
.await
173194
{

0 commit comments

Comments
 (0)