From 1140c0c592ebe3af49ffe24450c8c7609fcb2d8a Mon Sep 17 00:00:00 2001 From: Ilya Zlobintsev Date: Wed, 29 Jul 2026 23:24:46 +0300 Subject: [PATCH] chore: use typed login manager dbus proxy, only trigger on resume event --- lact-daemon/src/suspend.rs | 47 ++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/lact-daemon/src/suspend.rs b/lact-daemon/src/suspend.rs index 8027b9d3..980ced2d 100644 --- a/lact-daemon/src/suspend.rs +++ b/lact-daemon/src/suspend.rs @@ -2,20 +2,28 @@ use crate::server::handler::Handler; use futures::StreamExt; use std::time::Duration; use tracing::{error, info}; -use zbus::{Connection, Proxy}; +use zbus::{Connection, proxy}; -const SUSPEND_EVENT_COLLECT_DURATION: Duration = Duration::from_secs(3); +const SUSPEND_EVENT_COLLECT_DURATION: Duration = Duration::from_secs(2); pub async fn listen_events(handler: Handler) { match connect_proxy().await { - // Note: despite the name, the events get triggered both on suspend and resume - Ok(proxy) => match proxy.receive_signal("PrepareForSleep").await { + Ok(proxy) => match proxy.receive_prepare_for_sleep().await { Ok(mut stream) => { - while stream.next().await.is_some() { - info!("suspend/resume event detected, queueing config reload"); - handler - .notify_reload_gpus(SUSPEND_EVENT_COLLECT_DURATION) - .await; + while let Some(value) = stream.next().await { + match value.args() { + Ok(args) => { + if !args.start { + info!("resume event detected, queueing config reload"); + handler + .notify_reload_gpus(SUSPEND_EVENT_COLLECT_DURATION) + .await; + } + } + Err(err) => { + error!("could not get sleep events args: {err}"); + } + } } } Err(err) => error!("could not subscribe to suspend events: {err:#}"), @@ -27,14 +35,19 @@ pub async fn listen_events(handler: Handler) { error!("suspend/resume events will not be handled."); } -async fn connect_proxy() -> anyhow::Result> { +async fn connect_proxy() -> anyhow::Result> { let conn = Box::pin(Connection::system()).await?; - let proxy = Proxy::new_owned( - conn, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - ) - .await?; + let proxy = LoginManagerProxy::new(&conn).await?; Ok(proxy) } + +#[proxy( + interface = "org.freedesktop.login1.Manager", + default_service = "org.freedesktop.login1", + default_path = "/org/freedesktop/login1" +)] +pub trait LoginManager { + // Note: despite the name, the events get triggered both on suspend and resume. `start` is false on resume + #[zbus(signal)] + fn prepare_for_sleep(&self, start: bool) -> zbus::Result<()>; +}