From 9c62f19e4b80b6bcffde024698015d3a533cb944 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 16 Oct 2024 16:00:18 -0600 Subject: [PATCH] Make use of systemd scopes optional --- Cargo.toml | 6 ++++++ src/desktop.rs | 17 ++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a971b7a..8696f88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,12 @@ desktop = [ "dep:freedesktop-desktop-entry", "dep:mime", "dep:shlex", + "tokio?/io-util", + "tokio?/net", +] +# Enables launching desktop files inside systemd scopes +desktop-systemd-scope = [ + "desktop", "dep:zbus", ] # Enables keycode serialization diff --git a/src/desktop.rs b/src/desktop.rs index 51c12ee..21b50ac 100644 --- a/src/desktop.rs +++ b/src/desktop.rs @@ -5,7 +5,6 @@ use std::{ ffi::OsStr, path::{Path, PathBuf}, }; -use zbus::zvariant; #[derive(Debug, Clone, PartialEq, Eq)] pub enum IconSource { @@ -259,6 +258,7 @@ where // // Similar to what Gnome sets, for now. if let Some(pid) = crate::process::spawn(cmd).await { + #[cfg(feature = "desktop-systemd-scope")] if let Ok(session) = zbus::Connection::session().await { if let Ok(systemd_manager) = SystemdMangerProxy::new(&session).await { let _ = systemd_manager @@ -268,17 +268,19 @@ where &[ ( "Description".to_string(), - zvariant::Value::from("Application launched by COSMIC") + zbus::zvariant::Value::from("Application launched by COSMIC") .try_to_owned() .unwrap(), ), ( "PIDs".to_string(), - zvariant::Value::from(vec![pid]).try_to_owned().unwrap(), + zbus::zvariant::Value::from(vec![pid]) + .try_to_owned() + .unwrap(), ), ( "CollectMode".to_string(), - zvariant::Value::from("inactive-or-failed") + zbus::zvariant::Value::from("inactive-or-failed") .try_to_owned() .unwrap(), ), @@ -291,6 +293,7 @@ where } } +#[cfg(feature = "desktop-systemd-scope")] #[zbus::proxy( interface = "org.freedesktop.systemd1.Manager", default_service = "org.freedesktop.systemd1", @@ -301,7 +304,7 @@ trait SystemdManger { &self, name: &str, mode: &str, - properties: &[(String, zvariant::OwnedValue)], - aux: &[(String, Vec<(String, zvariant::OwnedValue)>)], - ) -> zbus::Result; + properties: &[(String, zbus::zvariant::OwnedValue)], + aux: &[(String, Vec<(String, zbus::zvariant::OwnedValue)>)], + ) -> zbus::Result; }