diff --git a/apps/desktop/desktop_native/core/src/powermonitor/linux.rs b/apps/desktop/desktop_native/core/src/powermonitor/linux.rs index 454487bce80..5306d75add9 100644 --- a/apps/desktop/desktop_native/core/src/powermonitor/linux.rs +++ b/apps/desktop/desktop_native/core/src/powermonitor/linux.rs @@ -1,7 +1,7 @@ -use std::borrow::Cow; +use std::{borrow::Cow, time::Duration}; use futures::TryStreamExt; -use zbus::{Connection, MatchRule}; +use zbus::{connection::Builder, Connection, MatchRule}; struct ScreenLock { interface: Cow<'static, str>, @@ -43,10 +43,18 @@ pub async fn on_lock(tx: tokio::sync::mpsc::Sender<()>) -> Result<(), Box zbus::Result { + Builder::session()? + .method_timeout(Duration::from_secs(2)) + .build() + .await +} + pub async fn is_lock_monitor_available() -> bool { - let connection = Connection::session().await.unwrap(); + let connection = match lock_monitor_connection().await { + Ok(connection) => connection, + Err(_) => return false, + }; for monitor in SCREEN_LOCK_MONITORS { let res = connection .call_method(