fix: prevent session from exiting

This commit is contained in:
Ashley Wulber 2023-06-30 18:45:31 -04:00 committed by Ashley Wulber
parent 30ce09f54a
commit e1a174f61d
4 changed files with 200 additions and 145 deletions

View file

@ -1,26 +1,23 @@
// SPDX-License-Identifier: GPL-3.0-only
use color_eyre::{eyre::WrapErr, Result};
use systemd_client::manager::{SystemdManagerProxy, SystemdManagerProxyBlocking};
pub async fn start_systemd_target() -> Result<()> {
let connection = zbus::Connection::session().await?;
let manager = SystemdManagerProxy::new(&connection)
.await
.wrap_err("failed to connect to org.freedesktop.systemd1.Manager")?;
manager
.start_unit("cosmic-session.target", "replace")
.await
.wrap_err("failed to start cosmic-session.target")?;
let _ = std::process::Command::new("systemctl")
.arg("start")
.arg("--user")
.arg("cosmic-session.target")
.spawn()
.wrap_err("Failed to start multi-user.target")?;
Ok(())
}
pub fn stop_systemd_target() -> Result<()> {
let connection = zbus::blocking::Connection::session().wrap_err("failed to connect to zbus")?;
let manager = SystemdManagerProxyBlocking::new(&connection)
.wrap_err("failed to connect to org.freedesktop.systemd1.Manager")?;
manager
.stop_unit("cosmic-session.target", "replace")
.wrap_err("failed to stop cosmic-session.target")?;
let _ = std::process::Command::new("systemctl")
.arg("stop")
.arg("--user")
.arg("cosmic-session.target")
.spawn()
.wrap_err("Failed to stop multi-user.target")?;
Ok(())
}