mirror of
https://github.com/ilya-zlobintsev/LACT.git
synced 2026-11-03 20:56:39 -06:00
chore: use typed login manager dbus proxy, only trigger on resume event
This commit is contained in:
1 parent
0995ba3ae0
commit
1140c0c592
1 file changed
+30
-17
+30
-17
@@ -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<Proxy<'static>> {
|
||||
async fn connect_proxy() -> anyhow::Result<LoginManagerProxy<'static>> {
|
||||
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<()>;
|
||||
}
|
||||
Reference in new issue
Block a user