Make use of systemd scopes optional

This commit is contained in:
Jeremy Soller 2024-10-16 16:00:18 -06:00
parent 2006d138eb
commit 9c62f19e4b
2 changed files with 16 additions and 7 deletions

View file

@ -33,6 +33,12 @@ desktop = [
"dep:freedesktop-desktop-entry", "dep:freedesktop-desktop-entry",
"dep:mime", "dep:mime",
"dep:shlex", "dep:shlex",
"tokio?/io-util",
"tokio?/net",
]
# Enables launching desktop files inside systemd scopes
desktop-systemd-scope = [
"desktop",
"dep:zbus", "dep:zbus",
] ]
# Enables keycode serialization # Enables keycode serialization

View file

@ -5,7 +5,6 @@ use std::{
ffi::OsStr, ffi::OsStr,
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use zbus::zvariant;
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum IconSource { pub enum IconSource {
@ -259,6 +258,7 @@ where
// //
// Similar to what Gnome sets, for now. // Similar to what Gnome sets, for now.
if let Some(pid) = crate::process::spawn(cmd).await { 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(session) = zbus::Connection::session().await {
if let Ok(systemd_manager) = SystemdMangerProxy::new(&session).await { if let Ok(systemd_manager) = SystemdMangerProxy::new(&session).await {
let _ = systemd_manager let _ = systemd_manager
@ -268,17 +268,19 @@ where
&[ &[
( (
"Description".to_string(), "Description".to_string(),
zvariant::Value::from("Application launched by COSMIC") zbus::zvariant::Value::from("Application launched by COSMIC")
.try_to_owned() .try_to_owned()
.unwrap(), .unwrap(),
), ),
( (
"PIDs".to_string(), "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(), "CollectMode".to_string(),
zvariant::Value::from("inactive-or-failed") zbus::zvariant::Value::from("inactive-or-failed")
.try_to_owned() .try_to_owned()
.unwrap(), .unwrap(),
), ),
@ -291,6 +293,7 @@ where
} }
} }
#[cfg(feature = "desktop-systemd-scope")]
#[zbus::proxy( #[zbus::proxy(
interface = "org.freedesktop.systemd1.Manager", interface = "org.freedesktop.systemd1.Manager",
default_service = "org.freedesktop.systemd1", default_service = "org.freedesktop.systemd1",
@ -301,7 +304,7 @@ trait SystemdManger {
&self, &self,
name: &str, name: &str,
mode: &str, mode: &str,
properties: &[(String, zvariant::OwnedValue)], properties: &[(String, zbus::zvariant::OwnedValue)],
aux: &[(String, Vec<(String, zvariant::OwnedValue)>)], aux: &[(String, Vec<(String, zbus::zvariant::OwnedValue)>)],
) -> zbus::Result<zvariant::OwnedObjectPath>; ) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
} }